mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-05 21:49:25 +08:00
Merge branch 'next' into develop
This commit is contained in:
commit
46df34b4f5
@ -80,3 +80,74 @@ describe('select query', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('select query with DB_TABLE_PREFIX', () => {
|
||||||
|
const model = class extends SQLModel {};
|
||||||
|
model.init(null, {
|
||||||
|
modelName: 'users',
|
||||||
|
tableName: 'd_users',
|
||||||
|
sequelize: new Sequelize({
|
||||||
|
dialect: 'postgres',
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
model.sql = 'SELECT * FROM "d_users"';
|
||||||
|
model.collection = {
|
||||||
|
fields: new Map(
|
||||||
|
Object.entries({
|
||||||
|
id: {},
|
||||||
|
name: {},
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
} as any;
|
||||||
|
const queryGenerator = model.queryInterface.queryGenerator as any;
|
||||||
|
|
||||||
|
test('plain sql', () => {
|
||||||
|
const query = queryGenerator.selectQuery('d_users', {}, model);
|
||||||
|
expect(query).toBe('SELECT * FROM "d_users";');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('attributes', () => {
|
||||||
|
const query = queryGenerator.selectQuery('d_users', { attributes: ['id', 'name'] }, model);
|
||||||
|
expect(query).toBe('SELECT "id", "name" FROM (SELECT * FROM "d_users") AS "users";');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('where', () => {
|
||||||
|
const query = queryGenerator.selectQuery('d_users', { where: { id: 1 } }, model);
|
||||||
|
expect(query).toBe('SELECT * FROM (SELECT * FROM "d_users") AS "users" WHERE "users"."id" = 1;');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('group', () => {
|
||||||
|
const query1 = queryGenerator.selectQuery('d_users', { group: 'id' }, model);
|
||||||
|
expect(query1).toBe('SELECT * FROM (SELECT * FROM "d_users") AS "users" GROUP BY "id";');
|
||||||
|
const query2 = queryGenerator.selectQuery('d_users', { group: ['id', 'name'] }, model);
|
||||||
|
expect(query2).toBe('SELECT * FROM (SELECT * FROM "d_users") AS "users" GROUP BY "id", "name";');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('order', () => {
|
||||||
|
const query = queryGenerator.selectQuery('d_users', { order: ['id'] }, model);
|
||||||
|
expect(query).toBe('SELECT * FROM (SELECT * FROM "d_users") AS "users" ORDER BY "users"."id";');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('limit, offset', () => {
|
||||||
|
const query = queryGenerator.selectQuery('d_users', { limit: 1, offset: 0 }, model);
|
||||||
|
expect(query).toBe('SELECT * FROM (SELECT * FROM "d_users") AS "users" LIMIT 1 OFFSET 0;');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('complex sql', () => {
|
||||||
|
const query = queryGenerator.selectQuery(
|
||||||
|
'd_users',
|
||||||
|
{
|
||||||
|
attributes: ['id', 'name'],
|
||||||
|
where: { id: 1 },
|
||||||
|
group: 'id',
|
||||||
|
order: ['id'],
|
||||||
|
limit: 1,
|
||||||
|
offset: 0,
|
||||||
|
},
|
||||||
|
model,
|
||||||
|
);
|
||||||
|
expect(query).toBe(
|
||||||
|
'SELECT "id", "name" FROM (SELECT * FROM "d_users") AS "users" WHERE "users"."id" = 1 GROUP BY "id" ORDER BY "users"."id" LIMIT 1 OFFSET 0;',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
@ -39,7 +39,7 @@ export function selectQuery(
|
|||||||
|
|
||||||
// Add WHERE to sub or main query
|
// Add WHERE to sub or main query
|
||||||
if (Object.prototype.hasOwnProperty.call(options, 'where')) {
|
if (Object.prototype.hasOwnProperty.call(options, 'where')) {
|
||||||
options.where = this.getWhereConditions(options.where, tableName, model, options);
|
options.where = this.getWhereConditions(options.where, model.name, model, options);
|
||||||
if (options.where) {
|
if (options.where) {
|
||||||
queryItems.push(` WHERE ${options.where}`);
|
queryItems.push(` WHERE ${options.where}`);
|
||||||
}
|
}
|
||||||
@ -48,8 +48,8 @@ export function selectQuery(
|
|||||||
// Add GROUP BY to sub or main query
|
// Add GROUP BY to sub or main query
|
||||||
if (options.group) {
|
if (options.group) {
|
||||||
options.group = Array.isArray(options.group)
|
options.group = Array.isArray(options.group)
|
||||||
? options.group.map((t) => this.aliasGrouping(t, model, tableName, options)).join(', ')
|
? options.group.map((t) => this.aliasGrouping(t, model, model.name, options)).join(', ')
|
||||||
: this.aliasGrouping(options.group, model, tableName, options);
|
: this.aliasGrouping(options.group, model, model.name, options);
|
||||||
|
|
||||||
if (options.group) {
|
if (options.group) {
|
||||||
queryItems.push(` GROUP BY ${options.group}`);
|
queryItems.push(` GROUP BY ${options.group}`);
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
"displayName.zh-CN": "通知:电子邮件",
|
"displayName.zh-CN": "通知:电子邮件",
|
||||||
"description": "Used for sending email notifications with built-in SMTP transport.",
|
"description": "Used for sending email notifications with built-in SMTP transport.",
|
||||||
"description.zh-CN": "通过电子邮件渠道发送通知,目前只支持 SMTP 传输方式。",
|
"description.zh-CN": "通过电子邮件渠道发送通知,目前只支持 SMTP 传输方式。",
|
||||||
|
"homepage": "https://docs.nocobase.com/handbook/notification-email",
|
||||||
|
"homepage.zh-CN": "https://docs-cn.nocobase.com/handbook/notification-email",
|
||||||
"main": "dist/server/index.js",
|
"main": "dist/server/index.js",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/nodemailer": "^6.x",
|
"@types/nodemailer": "^6.x",
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
"displayName.zh-CN": "通知:站内信",
|
"displayName.zh-CN": "通知:站内信",
|
||||||
"description": "It supports users in receiving real-time message notifications within the NocoBase application.",
|
"description": "It supports users in receiving real-time message notifications within the NocoBase application.",
|
||||||
"description.zh-CN": "支持用户在 NocoBase 应用内实时接收消息通知。",
|
"description.zh-CN": "支持用户在 NocoBase 应用内实时接收消息通知。",
|
||||||
|
"homepage": "https://docs.nocobase.com/handbook/notification-in-app-message",
|
||||||
|
"homepage.zh-CN": "https://docs-cn.nocobase.com/handbook/notification-in-app-message",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"Notification"
|
"Notification"
|
||||||
],
|
],
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
"displayName.zh-CN": "通知管理",
|
"displayName.zh-CN": "通知管理",
|
||||||
"description.zh-CN": "提供统一的管理服务,涵盖渠道配置、日志记录等功能,支持多种通知渠道的配置,包括站内信和电子邮件等。",
|
"description.zh-CN": "提供统一的管理服务,涵盖渠道配置、日志记录等功能,支持多种通知渠道的配置,包括站内信和电子邮件等。",
|
||||||
"version": "1.6.0-alpha.20",
|
"version": "1.6.0-alpha.20",
|
||||||
|
"homepage": "https://docs.nocobase.com/handbook/notification-manager",
|
||||||
|
"homepage.zh-CN": "https://docs-cn.nocobase.com/handbook/notification-manager",
|
||||||
"main": "dist/server/index.js",
|
"main": "dist/server/index.js",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@ant-design/icons": "5.x",
|
"@ant-design/icons": "5.x",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user