createCollection
Arguments
Definition (required)
Collection definition is a plain javascript object. In its simples form, it only needs a name
:
name
: a unique name to identify the collection. Required.attributes
: an object of column definitions. Optional.
Take a look at the example below:
Supported column types: string
, integer
, float
, boolean
, text
, date
, datetime
.
If you put a text value instead an object in a column, it'll automatically be translated as its column type.
For some types like: integer
, float
, boolean
, date
, and datetime
, it'll automatically put the right validator and sanitizer into account.
To hide some columns from result set, use hidden
property and set it to true
To transform the key to something else, use mask
property and set it to any key name.
Example:
You can also add column validators & sanitizers. These will guarantee that whatever you put in the database are in correct types and values.
Params (optional)
withSchema
: optional, defaults tofalse
. If settrue
, it'll destroy its internal database schema and rebuild a new one. In SQL database, this means very dangerous: drop existing table and recreate a new one with a schema built from the fields definition. All existing records & schema will be lost forever.
Response
Result
It should return an object like below:
Error
It'll yield Collection already exists error if the collection name has been used before.
Any other error will yield a normal Node error object you can catch through promise easily.
Last updated