Egg.js egg-mysql CRUD statement multi-table joint query of the same field

problem description

Multi-table federated query for egg-mysql CRUD statement for the same field.

official query code instance

const results = await this.app.mysql.select("posts", { //  post 
  where: { status: "draft", author: ["author1", "author2"] }, // WHERE 
  columns: ["author", "title"], // 
  orders: [["created_at","desc"], ["id","desc"]], // 
  limit: 10, // 
  offset: 0, // 
});

for example: both tables in mysql have a field, how to select the data of both tables.
mysql is written as: "select a.authoritative b.author form a where a.authoritative b.authoritative;

how to write according to egg.js.

May.14,2021

I also want to know that if I just encountered this problem, I can't just this.app.mysql.query ('sql')


I also encounter this problem, but my table is relatively simple. I directly create a view as a summary table, and then use egg-mysql 's select scheme to query the view.


has just made a more complex query, so I simply put the logic into the stored procedure, and then call the stored procedure directly.

< hr >

const queryResult = await app.mysql.query ('call proc_getFloorAndReply (?,?)', [ctx.userInfo.userId, lastId, pageSize]);

< hr >

of course it's a simple relational query. I think I'd better use the handwritten SQL and use the app.mysql.query method.


element-ui, egg.js, mysql, redis, front and rear separation, rights management, rapid development, different coding experience: https://cool-admin.com 's best egg background framework

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e52a69-4c8d5.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e52a69-4c8d5.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?