mirror of
https://github.com/nocodb/nocodb.git
synced 2026-02-01 23:38:21 +00:00
fix typings
This commit is contained in:
48
packages/nocodb/src/dbQueryClient/generic.ts
Normal file
48
packages/nocodb/src/dbQueryClient/generic.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { arrFlatMap } from 'nocodb-sdk';
|
||||
import type { DBQueryClient } from '~/dbQueryClient/types';
|
||||
import type { XKnex } from '~/db/CustomKnex';
|
||||
|
||||
export abstract class GenericDBQueryClient implements DBQueryClient {
|
||||
temporaryTableRaw({
|
||||
knex,
|
||||
data,
|
||||
fields,
|
||||
alias,
|
||||
}: {
|
||||
data: Record<string, any>[];
|
||||
fields: string[];
|
||||
alias: string;
|
||||
knex: XKnex;
|
||||
}) {
|
||||
const fieldsValuePlaceholder = `(${fields.map(() => '?').join(',')})`;
|
||||
const valuesPlaceholder = data.map(() => fieldsValuePlaceholder).join(', ');
|
||||
const fieldsPlaceholder = fields.map(() => '??').join(',');
|
||||
return knex.raw(
|
||||
`(VALUES ${valuesPlaceholder}) AS ?? (${fieldsPlaceholder})`,
|
||||
[
|
||||
...arrFlatMap(
|
||||
data.map((row) =>
|
||||
fields.reduce((acc, field) => {
|
||||
acc.push(row[field]);
|
||||
return acc;
|
||||
}, []),
|
||||
),
|
||||
),
|
||||
alias,
|
||||
...fields,
|
||||
],
|
||||
);
|
||||
}
|
||||
temporaryTable(param: {
|
||||
data: Record<string, any>[];
|
||||
fields: string[];
|
||||
alias: string;
|
||||
knex: XKnex;
|
||||
asKnexFrom?: boolean;
|
||||
}) {
|
||||
return param.knex.from(this.temporaryTableRaw(param));
|
||||
}
|
||||
|
||||
abstract concat(fields: string[]): string;
|
||||
abstract simpleCast(field: string, asType: string): string;
|
||||
}
|
||||
@@ -1,42 +1,10 @@
|
||||
import { arrFlatMap } from 'nocodb-sdk';
|
||||
import type { DBQueryClient } from '~/dbQueryClient/types';
|
||||
import type { XKnex } from '~/db/CustomKnex';
|
||||
|
||||
export class MySqlDBQueryClient implements DBQueryClient {
|
||||
temporaryTable({
|
||||
knex,
|
||||
data,
|
||||
fields,
|
||||
alias,
|
||||
asKnexFrom = true,
|
||||
}: {
|
||||
data: Record<string, any>[];
|
||||
fields: string[];
|
||||
alias: string;
|
||||
knex: XKnex;
|
||||
asKnexFrom?: boolean;
|
||||
}) {
|
||||
const fieldsValuePlaceholder = `(${fields.map(() => '?').join(',')})`;
|
||||
const valuesPlaceholder = data.map(() => fieldsValuePlaceholder).join(', ');
|
||||
const fieldsPlaceholder = fields.map(() => '??').join(',');
|
||||
const query = knex.raw(
|
||||
`(VALUES ${valuesPlaceholder}) AS ?? (${fieldsPlaceholder})`,
|
||||
[
|
||||
...arrFlatMap(
|
||||
data.map((row) =>
|
||||
fields.reduce((acc, field) => {
|
||||
acc.push(row[field]);
|
||||
return acc;
|
||||
}, []),
|
||||
),
|
||||
),
|
||||
alias,
|
||||
...fields,
|
||||
],
|
||||
);
|
||||
return asKnexFrom ? knex.from(query) : query;
|
||||
}
|
||||
import { GenericDBQueryClient } from '~/dbQueryClient/generic';
|
||||
|
||||
export class MySqlDBQueryClient
|
||||
extends GenericDBQueryClient
|
||||
implements DBQueryClient
|
||||
{
|
||||
concat(fields: string[]) {
|
||||
return `CONCAT(${fields.join(', ')})`;
|
||||
}
|
||||
|
||||
@@ -1,42 +1,10 @@
|
||||
import { arrFlatMap } from 'nocodb-sdk';
|
||||
import type { DBQueryClient } from '~/dbQueryClient/types';
|
||||
import type { XKnex } from '~/db/CustomKnex';
|
||||
|
||||
export class PGDBQueryClient implements DBQueryClient {
|
||||
temporaryTable({
|
||||
knex,
|
||||
data,
|
||||
fields,
|
||||
alias,
|
||||
asKnexFrom = true,
|
||||
}: {
|
||||
data: Record<string, any>[];
|
||||
fields: string[];
|
||||
alias: string;
|
||||
knex: XKnex;
|
||||
asKnexFrom?: boolean;
|
||||
}) {
|
||||
const fieldsValuePlaceholder = `(${fields.map(() => '?').join(',')})`;
|
||||
const valuesPlaceholder = data.map(() => fieldsValuePlaceholder).join(', ');
|
||||
const fieldsPlaceholder = fields.map(() => '??').join(',');
|
||||
const query = knex.raw(
|
||||
`(VALUES ${valuesPlaceholder}) AS ?? (${fieldsPlaceholder})`,
|
||||
[
|
||||
...arrFlatMap(
|
||||
data.map((row) =>
|
||||
fields.reduce((acc, field) => {
|
||||
acc.push(row[field]);
|
||||
return acc;
|
||||
}, []),
|
||||
),
|
||||
),
|
||||
alias,
|
||||
...fields,
|
||||
],
|
||||
);
|
||||
return asKnexFrom ? knex.from(query) : query;
|
||||
}
|
||||
import { GenericDBQueryClient } from '~/dbQueryClient/generic';
|
||||
|
||||
export class PGDBQueryClient
|
||||
extends GenericDBQueryClient
|
||||
implements DBQueryClient
|
||||
{
|
||||
concat(fields: string[]) {
|
||||
return `CONCAT(${fields.join(', ')})`;
|
||||
}
|
||||
|
||||
@@ -1,42 +1,10 @@
|
||||
import { arrFlatMap } from 'nocodb-sdk';
|
||||
import type { DBQueryClient } from '~/dbQueryClient/types';
|
||||
import type { XKnex } from '~/db/CustomKnex';
|
||||
|
||||
export class SqliteDBQueryClient implements DBQueryClient {
|
||||
temporaryTable({
|
||||
knex,
|
||||
data,
|
||||
fields,
|
||||
alias,
|
||||
asKnexFrom = true,
|
||||
}: {
|
||||
data: Record<string, any>[];
|
||||
fields: string[];
|
||||
alias: string;
|
||||
knex: XKnex;
|
||||
asKnexFrom?: boolean;
|
||||
}) {
|
||||
const fieldsValuePlaceholder = `(${fields.map(() => '?').join(',')})`;
|
||||
const valuesPlaceholder = data.map(() => fieldsValuePlaceholder).join(', ');
|
||||
const fieldsPlaceholder = fields.map(() => '??').join(',');
|
||||
const query = knex.raw(
|
||||
`(VALUES ${valuesPlaceholder}) AS ?? (${fieldsPlaceholder})`,
|
||||
[
|
||||
...arrFlatMap(
|
||||
data.map((row) =>
|
||||
fields.reduce((acc, field) => {
|
||||
acc.push(row[field]);
|
||||
return acc;
|
||||
}, []),
|
||||
),
|
||||
),
|
||||
alias,
|
||||
...fields,
|
||||
],
|
||||
);
|
||||
return asKnexFrom ? knex.from(query) : query;
|
||||
}
|
||||
import { GenericDBQueryClient } from '~/dbQueryClient/generic';
|
||||
|
||||
export class SqliteDBQueryClient
|
||||
extends GenericDBQueryClient
|
||||
implements DBQueryClient
|
||||
{
|
||||
concat(fields: string[]) {
|
||||
return `${fields.join(' || ')}`;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { XKnex } from '~/db/CustomKnex';
|
||||
import type { Knex, XKnex } from '~/db/CustomKnex';
|
||||
|
||||
export interface DBQueryClient {
|
||||
temporaryTable(payload: {
|
||||
@@ -6,8 +6,14 @@ export interface DBQueryClient {
|
||||
fields: string[];
|
||||
alias: string;
|
||||
knex: XKnex;
|
||||
asKnexFrom?: boolean;
|
||||
});
|
||||
}): Knex.QueryInterface;
|
||||
|
||||
temporaryTableRaw(payload: {
|
||||
data: Record<string, any>[];
|
||||
fields: string[];
|
||||
alias: string;
|
||||
knex: XKnex;
|
||||
}): Knex.Raw;
|
||||
|
||||
concat(fields: string[]);
|
||||
simpleCast(field: string, asType: string);
|
||||
|
||||
Reference in New Issue
Block a user