realglobe-Inc / clay-driver-sequelize

Clay driver for Sequelize
Apache License 2.0
1 stars 1 forks source link

where: { $gt: 1 } などは使えますか? #18

Open FujiHaruka opened 7 years ago

FujiHaruka commented 7 years ago

この辺の検索オプションは使えますか?

http://docs.sequelizejs.com/manual/tutorial/querying.html

$and: {a: 5}           // AND (a = 5)
$or: [{a: 5}, {a: 6}]  // (a = 5 OR a = 6)
$gt: 6,                // > 6
$gte: 6,               // >= 6
$lt: 10,               // < 10
$lte: 10,              // <= 10
$ne: 20,               // != 20
$eq: 3,                // = 3
$not: true,            // IS NOT TRUE
$between: [6, 10],     // BETWEEN 6 AND 10
$notBetween: [11, 15], // NOT BETWEEN 11 AND 15
$in: [1, 2],           // IN [1, 2]
FujiHaruka commented 7 years ago

@okunishinishi 日付も $gt が使いたいです。

'use strict'

const clayLump = require('clay-lump')
const { SqliteDriver } = require('clay-driver-sqlite')
const clayPolicy = require('clay-policy')
const { DATE } = clayPolicy.DataTypes
const moment = require('moment')
const assert = require('assert')

async function exampleClayLump () {
  let lump = clayLump('lump', {
    driver: new SqliteDriver('var/example-lump.db')
  })

  lump.resource('User').policy({
    creaetdAt: {
      type: DATE
    }
  })

  let today = moment().toDate()
  let yesterday = moment().subtract(1, 'days').toDate()

  const User = lump.resource('User')

  await User.drop()
  await User.create({ creaetdAt: today })
  await User.create({ creaetdAt: yesterday })

  let users = await User.list({
    filter: {
      creaetdAt: {
        $gt: yesterday
      }
    }
  })
  assert.equal(users.meta.length, 1)
  // -> Error
}

exampleClayLump().catch((err) => console.error(err))