How to use the sequelize.Op 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 ging / fiware-idm / controllers / web / applications.js View on Github external
var models = require('../../models/models.js');
var fs = require('fs');
var uuid = require('uuid');
var _ = require('lodash');

var config = require('../../config');

var Sequelize = require('sequelize');
const Op = Sequelize.Op;

var debug = require('debug')('idm:web-application_controller');
var gravatar = require('gravatar');
var Jimp = require("jimp");

var image = require ('../../lib/image.js');
var crypto = require('crypto'); 

// Autoload info if path include applicationId
exports.load_application = function(req, res, next, applicationId) {

	debug("--> load_application");

	if (applicationId === 'idm_admin_app') {
		// Reponse with message
		var response = {text: ' Application doesn`t exist.', type: 'danger'};
github nemanjam / rn-chat / server / src / data / logic.js View on Github external
import {
  ApolloError,
  AuthenticationError,
  ForbiddenError,
} from 'apollo-server';
import Sequelize from 'sequelize';
import { MessageModel, UserModel, GroupModel, ChatModel } from './connectors';

const Op = Sequelize.Op;

// reusable function to check for a user with context
function getAuthenticatedUser(ctx) {
  // return UserModel.findOne({ where: { id: 1 } });

  return ctx.user.then(user => {
    if (!user) {
      throw new AuthenticationError('Unauthenticated');
    }
    return user;
  });
}

async function isUserAuth(userId, ctx) {
  const authUser = await getAuthenticatedUser(ctx);
  if (authUser.id !== userId) {
github OriginProtocol / origin / infra / token-transfer-server / src / lib / lockup.js View on Github external
async function addLockup(userId, amount, data = {}) {
  const user = await hasBalance(userId, amount)

  const unconfirmedLockups = await Lockup.findAll({
    where: {
      userId: user.id,
      confirmed: null, // Unconfirmed
      created_at: {
        [Sequelize.Op.gte]: moment
          .utc()
          .subtract(lockupConfirmationTimeout, 'minutes')
      }
    }
  })

  if (unconfirmedLockups.length > 0) {
    throw new ReferenceError(
      'Unconfirmed lockups exist, please confirm or wait until expiry'
    )
  }

  let lockup
  const txn = await sequelize.transaction()
  try {
    lockup = await Lockup.create({
github d-band / koa-orm / lib / orm.js View on Github external
$strictLeft: Op.strictLeft,
      $strictRight: Op.strictRight,
      $noExtendRight: Op.noExtendRight,
      $noExtendLeft: Op.noExtendLeft,
      $and: Op.and,
      $or: Op.or,
      $any: Op.any,
      $all: Op.all,
      $values: Op.values,
      $col: Op.col
    };
    const sequelize = new Sequelize(db, config.username, config.password, options);

    // object for exports
    const database = {
      Op: Sequelize.Op,
      Sequelize: Sequelize,
      sequelize: sequelize,
      sync: sequelize.sync.bind(sequelize)
    };

    // squel & functions: query, queryOne
    Object.assign(database, sql(sequelize, options.dialect));

    // init models
    config.modelPath && Object.assign(database, models(sequelize, config.modelPath));

    databases[name] = database;
  });
github ramsaylanier / WordExpressSchema / src / modules / Thumbnail / connectors / getPostThumbnail.js View on Github external
import Sequelize from 'sequelize'
import shapeThumbnail from '../shapeThumbnail'

const Op = Sequelize.Op

export default function (Postmeta, Post, settings) {
  return function(postId) {
    return Postmeta.findOne({
      where: {
        post_id: postId,
        meta_key: '_thumbnail_id'
      }
    }).then(res => {
      if (res) {
        const {amazonS3} = settings.publicSettings
        const metaKeys = amazonS3 ? ['amazonS3_info'] : ['_wp_attached_file']
        metaKeys.push('_wp_attachment_metadata')

        return Post.findOne({
          where: {
github ArkEcosystem / core / app / database / sequelize / repositories / transactions.js View on Github external
const Op = require('sequelize').Op
const Transaction = require('../../../models/transaction')
const buildFilterQuery = require('../utils/filter-query')
const { TRANSACTION_TYPES } = require('../../../core/constants')

module.exports = class TransactionsRepository {
  constructor (db) {
    this.db = db
  }

  findAll (params) {
    let whereStatement = {}
    let orderBy = []

    const filter = ['type', 'senderPublicKey', 'recipientId', 'amount', 'fee', 'blockId']
    for (const elem of filter) {
      if (params[elem]) { whereStatement[elem] = params[elem] }
github volumio / Volumio2 / app / plugins / music_service / mpd / dbImplementation.js View on Github external
DBImplementation.prototype.searchTracks = function(searchValue) {
	var self = this;
	if (!searchValue) {
		return libQ.reject(new Error('DBImplementation.searchTracks: search value is empty'));
	}

	return this.library.searchTracks({
		where: {
			[Sequelize.Op.or]: {
				title: {[Sequelize.Op.substring]: searchValue}
			}
		},
		order: ['tracknumber'],
		raw: true
	}).then(function(trackArr) {
		return trackArr.map(function(track) {
			return self.track2SearchResult(track);
		});
	});
};
github codetrial / got-auth-service / app / model / app.js View on Github external
'use strict';

const Op = require('sequelize').Op;

module.exports = app => {
  const { STRING, INTEGER, DATE } = app.Sequelize;

  const App = app.model.define(
    'app',
    {
      id: { type: INTEGER, primaryKey: true, autoIncrement: true },
      code: { type: STRING(255), unique: 'code' },
      name: STRING(255),
      create_time: DATE,
      update_time: DATE,
    },
    {
      timestamps: true,
      createdAt: 'create_time',
github TaleLin / lin-cms-koa / app / dao / book.js View on Github external
async getBookByKeyword (q) {
    const book = await Book.findOne({
      where: {
        title: {
          [Sequelize.Op.like]: `%${q}%`
        },
        delete_time: null
      }
    });
    return book;
  }
github gzwgq222 / blog-server / controllers / category.js View on Github external
const Category = require('../model/category')
const Op = require('sequelize').Op

const listAll = async (ctx) => {
  const data = await Category.findAll()
  ctx.body = {
    code: 1000,
    data
  }
}

const list = async (ctx) => {
  const query = ctx.query
  const where = {
    name: {
      [Op.like]: `%${query.name}%`
    }
  }

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 28 days ago

Package Health Score

95 / 100
Full package analysis