bignosql
Smart NoSQL wrapper for SQL.
This isn't a ORM, it just simplify the SQL usage.
Installation
$ npm install --save bignosql # And one of the following: $ npm install --save pg # for postgresql $ npm install --save mysql # for mysql and like mysql
Usage
var bignosql = ;var client = bignosql;var model = client;model;model;model;model;model;model;
API
bignosql
Any
The variables definition for Schema Undefined type.
Don't direct usage the variable, it is local usage.
Number
The variables definiton for Schema Number type.
String
The variables definiton for Schema String type.
connect(type, parameters, [options])
Connect the sql database, return the Client object
Name | Type | Description |
---|---|---|
type | string | target sql type |
parameters | Object | the sql connect params |
options | Object(options) | the options for bignosql |
type & parameters
type: pgsql
use pg.pools, parameters details
type: mysql
use mysql.createPool parameters details
Object(Options)
Name | Type | Default | Description |
---|---|---|---|
debug | boolen | false | switch in debug message |
Client
model(name, schema)
Create a model for SQL Table, return Model object.
Name | Type | Description |
---|---|---|
name | string | the table name for sql |
schema | Object(Schema) | the schema definition |
Object(Schema)
The Schema is a simple object, Key is the column name, Value is a type definition.
The type definition may be a variable or Object(ShemaType).
Object(SchemaType)
Name | Type | Default | Description |
---|---|---|---|
type | variables | Any | column data type |
default | object | Undefined | default value for column |
Model
insert(doc, [options], callback)
Insert one record to table.
Name | Type | Description |
---|---|---|
doc | Object | the columns and it values |
options | Object(InsertOptions) | the options for insert |
callback | function | the callback for result |
Object(InsertOptions)
Name | Type | Default | Description |
---|---|---|---|
id | string | Undefined | for result the auto incriment name |
find(query, [fields], [callback])
Finds some records from table.
Name | Type | Description |
---|---|---|
query | Object | the columns and it conditions |
fields | Object | required column names |
callback | function | callback for result |
when callback was null, it return Query object
Object(Condition)
Key | Type | Description |
---|---|---|
$or | Array | OR condition array |
$in | Array | vlaue in a array |
$nin | Array | value not in a array |
$eq | Object | value = a object |
$ne | Object | value != a object |
$lt | number | value < a number |
$lte | number | value <= a number |
$gt | number | value > a number |
$gte | number | value >= a number |
$regex | string | value match a regexp string |
Query
select(fields)
Set required column names. It's a K/V Object, key is column name, V 1 or true was required.
sort(fields)
Set column sort order. It's a K/V Object, key is column name, V 1 was ASC, -1 was DESC.
skip(n)
Set skip row count in table
limit(n)
Set limit row count in result
exec(callback)
callback for result
count(query, callback)
Get count from table.
Name | Type | Description |
---|---|---|
query | Object | the columns and it conditions |
callback | function | callback for result |
update(query, update, [options], callback)
Update records from table.
Name | Type | Description |
---|---|---|
query | Object | the columns and it conditions |
update | Object(UpdateScript) | update script |
callback | function | callback for result |
Object(UpdateScript)
It was a simple record object like doc in insert, or a complex object.
Key | Type | Description |
---|---|---|
$set | doc | the record object |
$inc | Object | the K/V for number addition |
Object(UpdateOptions)
only supoort for pgsql
Name | Type | Default | Description |
---|---|---|---|
return | string | Undefined | for result a column |
remove(query, callback)
Remove records from table.
Name | Type | Description |
---|---|---|
query | Object | the columns and it conditions |
callback | function | callback for result |