不要怂,就是干,撸起袖子干!

output.md 6.15 KB

Sequelize

The main class


new Sequelize()

Instantiate sequelize with name of database, username and password

Example usage

// without password and options
var sequelize = new Sequelize('database', 'username')

// without options
var sequelize = new Sequelize('database', 'username', 'password')

// without password / with blank password
var sequelize = new Sequelize('database', 'username', null, {})

// with password and options
var sequelize = new Sequelize('my_database', 'john', 'doe', {})

// with uri (see below)
var sequelize = new Sequelize('mysql://localhost:3306/database', {})

Params:

Name Type Description
database String The name of the database
[username=null] String The username which is used to authenticate against the database.
[password=null] String The password which is used to authenticate against the database.
[options={}] Object An object with options.
[options.dialect='mysql'] String The dialect of the relational database.
[options.dialectModulePath=null] String If specified, load the dialect library from this path.
[options.host='localhost'] String The host of the relational database.
[options.port=] Integer The port of the relational database.
[options.protocol='tcp'] String The protocol of the relational database.
[options.define={}] Object Options, which shall be default for every model definition.
[options.query={}] Object I have absolutely no idea.
[options.sync={}] Object Options, which shall be default for every `sync` call.
[options.logging=console.log] Function A function that gets executed everytime Sequelize would log something.
[options.omitNull=false] Boolean A flag that defines if null values should be passed to SQL queries or not.
[options.queue=true] Boolean I have absolutely no idea.
[options.native=false] Boolean A flag that defines if native library shall be used or not.
[options.replication=false] Boolean I have absolutely no idea.
[options.pool={}] Object Something.
[options.quoteIdentifiers=true] Boolean Set to `false` to make table names and attributes case-insensitive on Postgres and skip double quoting of them.

new Sequelize()

Instantiate sequlize with an URI

Params:

Name Type Description
uri String A full database URI
[options={}] object See above for possible options


getDialect()

Returns the specified dialect.

Return:

  • String The specified dialect.

getQueryInterface()

Returns an instance of QueryInterface.

See: {QueryInterface}

Return:

  • QueryInterface An instance (singleton) of QueryInterface.

getMigrator([options={}], [force=false])

Returns an instance (singleton) of Migrator.

Params:

Name Type Description
[options={}] Object Some options
[force=false] Boolean A flag that defines if the migrator should get instantiated or not.

Return:

  • Migrator An instance of Migrator.

model(daoName)

Fetch a DAO factory

Params:

Name Type Description
daoName String The name of a model defined with Sequelize.define

query(sql, [callee], [options={}], [replacements])

Execute a query on the DB, with the posibility to bypass all the sequelize goodness.

See {@link MyClass} and [MyClass's foo property]{@link MyClass#foo}. Also, check out {@link http://www.google.com|Google} and {@link https://github.com GitHub}.

See: {DAOFactory#build} for more information about callee.

Params:

Name Type Description
sql String
[callee] DAOFactory If callee is provided, the selected data will be used to build an instance of the DAO represented by the factory. Equivalent to calling DAOFactory.build with the values provided by the query.
[options={}] Object Query options. See above for a full set of options
[replacements] Object|Array Either an object of named parameter replacements in the format `:param` or an array of unnamed replacements to replace `?`

query(sql, [options={raw:true}])

Execute a raw query against the DB.

Params:

Name Type Description
sql String
[options={raw:true}] Object Query options. See above for a full set of options

authenticate(cake, a)

Test the connetion by trying to authenticate

Params:

Name Type Description
cake boolean want cake?
a string something else

authenticate (k)

Test the connetion by trying to authenticate

Params:

Name Type Description
k string something else