查看“︁JavaScript/thinkjs/model”︁的源代码
来自康健生活
←
JavaScript/thinkjs/model
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
== model == == 复合查询 == 1. 复合查询,获取画板数组,关联表为画板表和画板历史表。sql 语句为。 {{Leftrightflex|<syntaxhighlight lang="javascript"> let result = await designArtboardModel.join({ table: 'design_artboard_history', as: 'dah', join: 'left', on: ['history_id', 'id'] }).field(`${prefix}design_artboard.id, ${prefix}design_artboard.name, ${prefix}design_artboard.team_id, ${prefix}design_artboard.work_id, ${prefix}design_artboard.group_id, ${prefix}design_artboard.history_id, ${prefix}design_artboard.resource, ${prefix}design_artboard.format, ${prefix}design_artboard.x, ${prefix}design_artboard.y, ${prefix}design_artboard.width, ${prefix}design_artboard.height, dah.create_time, dah.message`) .where({[`${prefix}design_artboard.team_id`]: team_id, [`${prefix}design_artboard.work_id`]: work_id, ...where}) .order(`${prefix}design_artboard.name`) .select();</syntaxhighlight>|<syntaxhighlight lang="mysql">SELECT md_design_artboard.id, md_design_artboard.name, md_design_artboard.team_id, md_design_artboard.work_id, md_design_artboard.group_id, md_design_artboard.history_id, md_design_artboard.resource, md_design_artboard.format, md_design_artboard.x, md_design_artboard.y, md_design_artboard.width, md_design_artboard.height, dah.create_time, dah.message FROM `md_design_artboard` LEFT JOIN `md_design_artboard_history` AS `dah` ON `md_design_artboard`.`history_id` = `dah`.`id` WHERE ( md_design_artboard.team_id = '54' ) AND ( md_design_artboard.work_id = '82' ) ORDER BY md_design_artboard.name ; </syntaxhighlight> }} 或者 {{Leftrightflex|<syntaxhighlight lang="javascript"> let result = await designArtboardModel.alias('adh').join({ table: 'design_artboard_history', as: 'dah', join: 'left', on: ['history_id', 'id'] }).field( `adh.id, adh.name, adh.team_id, adh.work_id, adh.group_id, adh.history_id, adh.resource, adh.format, adh.x, adh.y, adh.width, adh.height, dah.create_time, dah.message`) .where({[`adh.team_id`]: team_id, [`adh.work_id`]: work_id, ...where}) .order(`adh.name`) .select();</syntaxhighlight>|<syntaxhighlight lang="mysql"> SELECT adh.id,adh.name, adh.team_id, adh.work_id, adh.group_id, adh.history_id, adh.resource, adh.format, adh.x, adh.y, adh.width, adh.height, dah.create_time, dah.message FROM `md_design_artboard` AS adh LEFT JOIN `md_design_artboard_history` AS `dah` ON `adh`.`history_id` = `dah`.`id` WHERE ( adh.team_id = '54' ) AND ( adh.work_id = '82' ) ORDER BY adh.name ;</syntaxhighlight>}} 输出结果: <pre>[ RowDataPacket { id: 604, name: '2-图层和颜色-19', team_id: 54, work_id: 82, group_id: 50, history_id: 165, resource: 'E3DCE35C-F4AF-4B1E-9014-A6F3A899B42D', format: 'sketch', x: 510, y: -227, width: '721', height: '1536', create_time: '2021-07-14 01:21:17', message: '' }, RowDataPacket { id: 608, name: 'Screenshot from 2021-06-25 16-55-22', team_id: 54, work_id: 82, group_id: 0, history_id: 169, resource: 'C6425DC1-B6A0-5037-1657-A710639CE686', format: 'png', x: 0, y: 1936, width: '1920', height: '1080', create_time: '2021-07-14 19:23:20', message: '' }, RowDataPacket { id: 606, name: '无封面', team_id: 54, work_id: 82, group_id: 0, history_id: 167, resource: 'C93CF7B7-AACE-D36C-3BD9-8581594DDBCA', format: 'png', x: 2020, y: 1936, width: '240', height: '225', create_time: '2021-07-14 14:34:41', message: '' } ] </pre> 多个 join。 {{Leftrightflex|<syntaxhighlight lang="javascript">await designArtboardModel.alias('adh').join({ table: 'design_artboard_history', as: 'dah', join: 'left', on: ['history_id', 'id'] }).join({ table: 'team', as: 't', join: 'left', on: ['team_id', 'id'] }).join({ table: 'work', as: 'w', join: 'left', on: ['work_id', 'id'] }).field(`adh.id, adh.name, adh.team_id, adh.work_id, adh.group_id, adh.history_id, adh.resource, adh.format, adh.x, adh.y, adh.width, adh.height, t.name as t_name, w.name as w_name, dah.create_time, dah.version, dah.message`).where({ [`adh.team_id`] : team_id, [`adh.work_id`] : work_id, ...where }).order(`adh.name`).select(); </syntaxhighlight> |<syntaxhighlight lang="MySQL">SELECT adh.id, adh.name, adh.team_id, adh.work_id, adh.group_id , adh.history_id, adh.resource, adh.format, adh.x, adh.y , adh.width, adh.height, t.name AS t_name, w.name AS w_name, dah.create_time , dah.version, dah.message FROM `md_design_artboard` adh LEFT JOIN `md_design_artboard_history` `dah` ON `adh`.`history_id` = `dah`.`id` LEFT JOIN `md_team` `t` ON `adh`.`team_id` = `t`.`id` LEFT JOIN `md_work` `w` ON `adh`.`work_id` = `w`.`id` WHERE adh.team_id = '10' AND adh.work_id = '192' ORDER BY adh.name </syntaxhighlight>}}
此页面嵌入的页面:
模板:Double-columns
(
查看源代码
)
模板:Double-columns/style.css
(
查看源代码
)
返回
JavaScript/thinkjs/model
。
导航菜单
康健生活
搜索
user-page
通知
user-interface-preferences
个人工具
登录
五一
多读书,多运动,多到远处走走,再看看不一样的世界。