我想弄清楚如何使Sequelize.js查詢輸出類似於查詢從GraphQL到Sequelize.js SELECT ... WHERE COL1 = X和(COL2像Y或COL3像Y)
SELECT ... WHERE C1 = X AND (C2 LIKE '%Y%' OR C3 LIKE '%Y%')... to MySQL
代碼
const resolvers = {
Query: {
findItems(_, args) {
return Item.findAll({
limit: 10,
active: 1,
offset: args.offset,
order: [['created_at', 'DESC']],
$or: [
{
column_a: {
$like: args.y,
},
},
{
column_b: {
$like: args.y,
},
}]
});
}
}
}
它從GraphQL
012查詢SELECT * FROM item ORDER BY created_at DESC LIMIT...
(任何地方)
模式
const typeDefinitions = `
type Item {
column_a: String,
column_b: String,
active: Int,
}
type Query {
findItems(column_a: String, column_b: String, active: Int, offset: Int): [Item]
}
type Mutation {
//..
}
schema {
query: Query
mutation: Mutation
}`;
export default [typeDefinitions];
來自Sequelize.js的文檔沒有解釋如何執行此查詢,我不知道該問題是否也來自GraphQL查詢。
這裏的查詢
{
findItems(column_a: "hello", column_b:"hello", active: 1, offset: 0) {
column_a
column_b
active
created_at
}
}
SELECT * FROM item ORDER BY created_at DESC LIMIT...
(任何地方)