Node.js学习10~Sequelize基本sql学习
Posted 秋9
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Node.js学习10~Sequelize基本sql学习相关的知识,希望对你有一定的参考价值。
Sequelize常用的select,delete,update,insert列表如下:
sql | orm |
---|---|
select | findAll,findOne,findById,findOrCreate,findAndCountAll |
delete | destroy |
update | update |
insert | create |
select举例:
sql | orm |
---|---|
SELECT foo, bar ... | Model.findAll(attributes: ['foo', 'bar']); |
SELECT foo, bar AS baz ... | Model.findAll(attributes: ['foo', ['bar', 'baz']]); |
SELECT COUNT(hats) AS no_hats ... | Model.findAll(attributes: [[sequelize.fn('COUNT', sequelize.col('hats')), 'no_hats']]); |
SELECT id, foo, bar, quz ... | Model.findAll(attributes: exclude: ['baz'] ); |
where条件,这个是学习重点
op | define |
$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 |
$between: [6, 10], | BETWEEN 6 AND 10 |
$notBetween: [11, 15], | NOT BETWEEN 11 AND 15 |
$in: [1, 2], | IN [1, 2] |
$notIn: [1, 2], | NOT IN [1, 2] |
$like: '%hat', | LIKE '%hat' |
$notLike: '%hat' | NOT LIKE '%hat' |
$iLike: '%hat' | ILIKE '%hat' (case insensitive) (PG only) |
$notILike: '%hat' | NOT ILIKE '%hat' (PG only) |
$like: $any: ['cat', 'hat'] | LIKE ANY ARRAY['cat', 'hat'] - also works for iLike and notLike |
$overlap: [1, 2] | && [1, 2] (PG array overlap operator) |
$contains: [1, 2] | @> [1, 2] (PG array contains operator) |
$contained: [1, 2] | <@ [1, 2] (PG array contained by operator) |
$any: [2,3] | ANY ARRAY[2, 3]::INTEGER (PG only) |
$col: 'user.organization_id' | "user"."organization_id", with dialect specific column identifiers, PG in this example --$col取表的字段 |
以上是关于Node.js学习10~Sequelize基本sql学习的主要内容,如果未能解决你的问题,请参考以下文章
node.js Sequelize操作mysql基本的增删改查demo
Node.js Sequelize UUID 主键 + Postgres
Node.js:如何在 Sequelize 中使用 Postgres 存储过程?