Sequelize-typescript: $between syntax not working

Created on 29 Mar 2019  路  11Comments  路  Source: RobinBuschmann/sequelize-typescript

The standard $between syntax doesn't seem to be working for typescript, is there an alternative syntax I have to use?

const games = await GamesDbGame.findAll({
            where: {
                id: {
                    $between: [0, 999999]
                }
            }
        });
Executing (default): SELECT `id`, `game_title`, `release_date`, `players`, `overview`, `last_updated`, `rating`, `coop`, `youtube`, `alternates`, `createdAt`, `updatedAt`, `platformId` FROM `GamesDbGames` AS `GamesDbGames` WHERE `GamesDbGames`.`id` = '[object Object]';

Most helpful comment

You must use a symbol operator because $ notation is deprecated

// ...model import...
import { Sequelize } from 'sequelize-typescript';
const { Op } = Sequelize;

const games = await GamesDbGame.findAll({
            where: {
                id: {
                    [Op.between]: [0, 999999]
                }
            }
        });

All 11 comments

You must use a symbol operator because $ notation is deprecated

// ...model import...
import { Sequelize } from 'sequelize-typescript';
const { Op } = Sequelize;

const games = await GamesDbGame.findAll({
            where: {
                id: {
                    [Op.between]: [0, 999999]
                }
            }
        });

You must use a symbol operator because $ notation is deprecated

// ...model import...
import { Sequelize } from 'sequelize-typescript';
const { Op } = Sequelize;

const games = await GamesDbGame.findAll({
            where: {
                id: {
                    [Op.between]: [0, 999999]
                }
            }
        });

Perfect thanks, Was trying to do:

import { Sequelize } from 'sequelize-typescript';
Sequelize.Op.between 
//or
$between

Going to re-open, the syntax above does "work" e.g.

import { Sequelize } from 'sequelize-typescript';
const { Op } = Sequelize;

But it also throws an error with the typescript compiler as Op doesn't seem to exist in the typings?

error TS2459: Type 'typeof Sequelize' has no property 'Op' and no string index signature.

@ian-callaghan
Which version of sequelize, sequelize-typescript, @types/sequelize do you use? Try to update to the latest versions.

@ian-callaghan
Which version of sequelize, sequelize-typescript, @types/sequelize do you use? Try to update to the latest versions.

reinstalled the packages but get the same error.

        "@types/sequelize": "^4.27.46",
        "@types/bluebird": "^3.5.26",
        "@types/validator": "^10.11.0",
        "sequelize": "^5.2.9",
        "sequelize-typescript": "^1.0.0-alpha.9",
        "reflect-metadata": "^0.1.13",

Could you show where the definition is in the .d.ts files so I can check it is there in mine?

Try latest stable version of sequelize-typescript

sequelize-typescript

Same error with @0.6.9 plus compiler throws a ton of errors about other things in the .d.ts file.

Managed to solve importing from sequelize although oddly that does not come up as an autocomplete option:

import { Op } from 'sequelize';

I also tries from sequelize/types which is in autocomplete but that also threw a compiler error:

import { Op } from 'sequelize/types';

Do you have an example of the above code working with it imported from sequelize-typescript properly?

@ian-callaghan
try this

import { Sequelize } from 'sequelize-typescript';
const { or } = Sequelize;

Account.findOne({ where: or({email: '[email protected]'}, {phone: '111111111111'})});

oh sorry, between is not exported from sequelize-typescript.
try this one,

import { Op } from 'sequelize';
await GamesDbGame.findAll({
            where: {
                id: {
                    [Op.between]: [0, 999999]
                }
            }
        });

oh sorry, between is not exported from sequelize-typescript.
try this one,

import { Op } from 'sequelize';
await GamesDbGame.findAll({
            where: {
                id: {
                    [Op.between]: [0, 999999]
                }
            }
        });

That's what I ended up doing, it works fine no errors, just a little odd that vs code auto import doesn't show it properly and instead tries to import it from 'sequelize/types'.

@ian-callaghan can we close this issue now?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

oscarcalvo picture oscarcalvo  路  3Comments

JustGreg picture JustGreg  路  4Comments

libvirtadept picture libvirtadept  路  4Comments

fareshan picture fareshan  路  3Comments

lverledens picture lverledens  路  4Comments