Skip to content

Instantly share code, notes, and snippets.

@maxkoryukov
Last active March 31, 2016 05:40
Show Gist options
  • Save maxkoryukov/71ca090953c788b34b67243170226ee6 to your computer and use it in GitHub Desktop.
Save maxkoryukov/71ca090953c788b34b67243170226ee6 to your computer and use it in GitHub Desktop.

Revisions

  1. maxkoryukov revised this gist Mar 31, 2016. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions sequelize-cheat-sheat.md
    Original file line number Diff line number Diff line change
    @@ -66,6 +66,7 @@ p.update({
    .then(x => {
    // TODO : define type of promise arg
    })
    ```

    ### Without any instances

  2. maxkoryukov revised this gist Mar 31, 2016. 1 changed file with 29 additions and 1 deletion.
    30 changes: 29 additions & 1 deletion sequelize-cheat-sheat.md
    Original file line number Diff line number Diff line change
    @@ -50,4 +50,32 @@ builder.findById(bid, {

    // -> returns `promise` around delete counter
    });
    ```
    ```

    ## Update

    ### Using persisted instance

    ```js

    // let p = person.findById ... - assume, you already have found the instance

    p.update({
    surname: 'new value'
    })
    .then(x => {
    // TODO : define type of promise arg
    })

    ### Without any instances

    ```js
    person.update(
    { note: 'new value' },
    {
    fields: ['note'],
    where: {id: id}
    }
    ).then( x => {
    }); // TODO : type of x , don't know what it is...
    ```
  3. maxkoryukov revised this gist Mar 30, 2016. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions sequelize-cheat-sheat.md
    Original file line number Diff line number Diff line change
    @@ -3,8 +3,7 @@
    <a id="many-to-many">
    ## Many to many

    ```
    ```js
    var person = sequelize.define("person", {
    id: {
    type: DataTypes.INTEGER,
  4. maxkoryukov renamed this gist Mar 30, 2016. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  5. maxkoryukov created this gist Mar 30, 2016.
    54 changes: 54 additions & 0 deletions sequelize-cheat-shet.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,54 @@
    # Sequelize Cheat Sheet

    <a id="many-to-many">
    ## Many to many

    ```
    var person = sequelize.define("person", {
    id: {
    type: DataTypes.INTEGER,
    allowNull: false,
    primaryKey: true,
    autoIncrement: true
    },
    name: DataTypes.STRING(500),
    phone: DataTypes.STRING(500),
    });
    var employee = sequelize.define("employee", {
    id: {
    type: DataTypes.INTEGER,
    allowNull: false,
    primaryKey: true,
    autoIncrement: true
    },
    job: DataTypes.STRING(500),
    });
    var builder = sequelize.define("builder", {
    id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true
    },
    name: DataTypes.STRING(100),
    });
    builder.belongsToMany(person, {as: 'employees', through: employee});
    person.belongsToMany(builder, {as: 'employers', through: employee});
    builder.findById(bid, {
    include: [{
    model: person,
    as: 'employees',
    }]
    })
    .then( builder => {
    // UNLINK:
    return b.removeEmployee(eid);
    // -> returns `promise` around delete counter
    });
    ```