packages/flux-capacitor-sequelize/lib/connectTo.js
function connectTo (connectionSettings, createCollections) {
  const sequelize = new Sequelize(connectionSettings)
  const collections = createCollections(sequelize, createCollection)

  const database = {
    /** @property {Sequelize} connection */
    connection: sequelize,

    /** @property {Object} collections    { [name: string]: Collection } */
    collections: collectionsAsKeyValue(collections),

    applyChangeset (changeset, options) {
      options = options || { transaction: null }
      return changeset.apply(options.transaction)
    },

    createEventId () {
      return uuid.v4()
    },

    transaction (callback) {
      return sequelize.transaction((sequelizeTransaction) => {
        const transaction = createTransaction(database, sequelizeTransaction)
        return callback(transaction)
      })
    }
  }

  return sequelize.sync().then(() => database)
}
function connectTo (connectionSettings, createCollections) {
  const sequelize = new Sequelize(connectionSettings)
  const collections = createCollections(sequelize, createCollection)

  const database = {
    /** @property {Sequelize} connection */
    connection: sequelize,

    /** @property {Object} collections    { [name: string]: Collection } */
    collections: collectionsAsKeyValue(collections),

    applyChangeset (changeset, options) {
      options = options || { transaction: null }
      return changeset.apply(options.transaction)
    },

    createEventId () {
      return uuid.v4()
    },

    transaction (callback) {
      return sequelize.transaction((sequelizeTransaction) => {
        const transaction = createTransaction(database, sequelizeTransaction)
        return callback(transaction)
      })
    }
  }

  return sequelize.sync().then(() => database)
}
function connectTo ( connectionSettings , createCollections ) { const sequelize = new Sequelize ( connectionSettings ) const collections = createCollections ( sequelize , createCollection ) const database = { /** @property {Sequelize} connection */ connection : sequelize , /** @property {Object} collections    { [name: string]: Collection } */ collections : collectionsAsKeyValue ( collections ) , applyChangeset ( changeset , options ) { options = options || { transaction : null } return changeset . apply ( options . transaction ) } , createEventId ( ) { return uuid . v4 ( ) } , transaction ( callback ) { return sequelize . transaction ( ( sequelizeTransaction ) => { const transaction = createTransaction ( database , sequelizeTransaction ) return callback ( transaction ) } ) } } return sequelize . sync ( ) . then ( ( ) => database ) }
Connect to a database using Sequelize ORM.

@param {string|object} connectionSettings  Connection URL like `sqlite://path/to/db.sqlite` or object: `{ database: string, host: string, dialect: string, ... }`
@param {Function} createCollections        (sequelize: Sequelize, createCollection: (name: string, model: Sequelize.Model) => Collection) => Array<Collection>
@return {Database}
Connect to a database using Sequelize ORM .