How to use the sequelize.JSON function in sequelize

To help you get started, we’ve selected a few sequelize examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github youphonic / youphonic / server / api / plays / play.model.js View on Github external
'use strict';

const Sequelize = require('sequelize');
var db = require('../../_db');
const bcrypt = require('bcrypt');

const Play = db.define('plays', {
	title: {
		type: Sequelize.STRING,
		allowNull: false
	},
  playJson: {
	  type: Sequelize.JSON,
	  allowNull: false
  },
	hashedPlay: {
		type: Sequelize.STRING
	},
	image: {
		type: Sequelize.TEXT
	}
}, {
	hooks: {
		beforeValidate: setHashedPlay,
		beforeUpdate: setHashedPlay
	}
});

	// hash the play data to use as secure parameter in get one route for sharing model
github SideProjectGuys / invite-manager-bot / src / sequelize.ts View on Github external
export interface SettingAttributes extends BaseAttributes {
	id: number;
	guildId: string;
	value: SettingsObject;
}
export interface SettingInstance extends Sequelize.Instance, SettingAttributes {
	getGuild: Sequelize.BelongsToGetAssociationMixin;
}

export const settings = sequelize.define(
	'setting',
	{
		id: { type: Sequelize.INTEGER, primaryKey: true, autoIncrement: true },
		guildId: Sequelize.STRING(32),
		value: Sequelize.JSON
	},
	{
		timestamps: true,
		paranoid: true,
		indexes: [
			{
				unique: true,
				fields: ['guildId']
			}
		]
	}
);
settings.belongsTo(guilds);
guilds.hasMany(settings);

// ------------------------------------
github zhanwenchen / blog / server / models / Post.js View on Github external
string_id: {
          type: Sequelize.STRING,
          allowNull: true,
          // allowNull: false,
          unique: true,
        },
        title: {
          type: Sequelize.STRING,
          allowNull: false,
        },
        body: {
          type: Sequelize.TEXT,
          allowNull: false,
        },
        assets: {
          type: Sequelize.JSON,
          allowNull: true,
        },
      }, {
        sequelize,
        hooks: {
          // TODO: {blog post} beforeValidate instead of beforeCreate, because beforeValidate runs before beforeCreate.
          beforeValidate: (post) => {
            post.string_id = post.title.replace(/\s+/g, '-').toLowerCase();
          },
        },
      });
    }
github staticdeploy / staticdeploy / storage / src / models / Entrypoint.ts View on Github external
export default (sequelize: Sequelize.Sequelize): typeof EntrypointModel => {
    EntrypointModel.init(
        {
            id: { type: Sequelize.STRING, primaryKey: true },
            appId: { type: Sequelize.STRING },
            bundleId: { type: Sequelize.STRING },
            redirectTo: { type: Sequelize.STRING },
            urlMatcher: { type: Sequelize.STRING },
            configuration: { type: Sequelize.JSON },
            createdAt: { type: Sequelize.DATE },
            updatedAt: { type: Sequelize.DATE }
        },
        {
            sequelize: sequelize,
            tableName: ENTRYPOINTS_TABLE
        }
    );

    return EntrypointModel;
};
github coding-blocks / hiring-blocks / db / models.js View on Github external
} catch (e) {
  console.error('Create your own secrets file lazybones');
  secret = require('../secret-sample.json')
}

const DATABASE_URL = process.env.DATABASE_URL || ('postgres://' + secret.DB_USER + ":" + secret.DB_PASSWORD + "@" + secret.DB_HOST + ":5432/" + secret.DATABASE);


const db = new Sequelize(DATABASE_URL, {
  dialect: 'postgres'
});


const Student = db.define('student', {
  id: {type: Sequelize.INTEGER, primaryKey: true, autoIncrement: true},
  education: Sequelize.ARRAY(Sequelize.JSON),
  skills: Sequelize.ARRAY(Sequelize.JSON),
  compLanguages: Sequelize.ARRAY(Sequelize.JSON),
  projects: Sequelize.ARRAY(Sequelize.JSON),
  trainings: Sequelize.ARRAY(Sequelize.JSON),
  cbStudent: {type: Sequelize.BOOLEAN, defaultValue: false},
  cbCourses: Sequelize.ARRAY(Sequelize.STRING),
});

const CompanyManager = db.define('companymanager', {
  id: {type: Sequelize.INTEGER, primaryKey: true, autoIncrement: true},
  designation: Sequelize.STRING,
});


const Admin = db.define('admin', {
  id: {type: Sequelize.INTEGER, primaryKey: true, autoIncrement: true},
github Feverqwe / ytWatchBot / src / db.js View on Github external
}, {
        name: 'channelId_idx',
        fields: ['channelId']
      }, {
        name: 'createdAt_idx',
        fields: ['createdAt']
      }]
    });
    ChatIdChannelId.belongsTo(Chat, {foreignKey: 'chatId', targetKey: 'id', onUpdate: 'CASCADE', onDelete: 'CASCADE'});
    ChatIdChannelId.belongsTo(Channel, {foreignKey: 'channelId', targetKey: 'id', onUpdate: 'CASCADE', onDelete: 'CASCADE'});

    const Video = this.sequelize.define('video', {
      id: {type: Sequelize.STRING(191), allowNull: false, primaryKey: true},
      url: {type: Sequelize.STRING(191), allowNull: false},
      title: {type: Sequelize.STRING(191), allowNull: false},
      previews: {type: Sequelize.JSON, allowNull: false},
      duration: {type: Sequelize.STRING(191), allowNull: true},
      channelId: {type: Sequelize.STRING(191), allowNull: false},
      publishedAt: {type: Sequelize.DATE, allowNull: false},
      telegramPreviewFileId: {type: Sequelize.TEXT, allowNull: true},
      mergedId: {type: Sequelize.STRING(191), allowNull: true},
      mergedChannelId: {type: Sequelize.STRING(191), allowNull: true},
    }, {
      tableName: 'videos',
      timestamps: true,
      updatedAt: false,
      indexes: [{
        name: 'publishedAt_idx',
        fields: ['publishedAt']
      }]
    });
    Video.belongsTo(Channel, {foreignKey: 'channelId', targetKey: 'id', onUpdate: 'CASCADE', onDelete: 'CASCADE'});
github ArkEcosystem / core / app / database / sequelize / schema.js View on Github external
uniqueKeys: {
      rounds_unique: {
        fields: ['publicKey', 'round']
      }
    },
    indexes: [{
      fields: ['publicKey']
    }, {
      fields: ['round']
    }]
  })

  const webhooks = db.define('webhooks', {
    event: Sequelize.STRING,
    target: Sequelize.STRING,
    conditions: Sequelize.JSON,
    secret: Sequelize.STRING,
    enabled: Sequelize.BOOLEAN
  }, {
    indexes: [{
      fields: ['event']
    }]
  })

  return Promise.all([blocks, transactions, wallets, rounds, webhooks].map(table => table.sync()))
}
github projectsolace / solace-admin / db / models / recording.js View on Github external
'use strict'

const Sequelize = require('sequelize')
const db = require('APP/db')

const Recording = db.define('recordings', {
  text: {
    type: Sequelize.TEXT,
    allowNull: false,
  },
  personality: Sequelize.JSON,
  tone: Sequelize.JSON,
  created_at: Sequelize.DATE
});

module.exports = Recording;
github staticdeploy / staticdeploy / storage / src / migrations / 00.ts View on Github external
allowNull: false
        },
        tag: {
            type: Sequelize.STRING,
            allowNull: false
        },
        description: {
            type: Sequelize.TEXT,
            allowNull: false
        },
        hash: {
            type: Sequelize.STRING,
            allowNull: false
        },
        assets: {
            type: Sequelize.JSON,
            allowNull: false
        },
        createdAt: {
            type: Sequelize.DATE,
            allowNull: false
        }
    });

    await q.createTable(APPS_TABLE, {
        id: {
            type: Sequelize.STRING,
            primaryKey: true
        },
        name: {
            type: Sequelize.STRING,
            unique: true,
github logerzhu / simple-graphql / src / type / index.js View on Github external
name: 'Boolean',
      graphQLInputType: GraphQLBoolean,
      graphQLOutputType: GraphQLBoolean,
      columnType: Sequelize.BOOLEAN
    }),
    Date: new ScalarFieldType({
      name: 'Date',
      graphQLInputType: GraphQLScalarTypes.Date,
      graphQLOutputType: GraphQLScalarTypes.Date,
      columnType: Sequelize.DATE
    }),
    JSON: new ScalarFieldType({
      name: 'JSON',
      graphQLInputType: GraphQLScalarTypes.Json,
      graphQLOutputType: GraphQLScalarTypes.Json,
      columnType: Sequelize.JSON
    })
  } : {[id:string]:ScalarFieldType})
}

sequelize

Sequelize is a promise-based Node.js ORM tool for Postgres, MySQL, MariaDB, SQLite, Microsoft SQL Server, Amazon Redshift and Snowflake’s Data Cloud. It features solid transaction support, relations, eager and lazy loading, read replication and more.

MIT
Latest version published 11 days ago

Package Health Score

95 / 100
Full package analysis