Browse Source

Merge pull request #5134 from nocodb/fix/various-sqlclient

fix: ts types for sql clients
pull/5167/head
mertmit 2 years ago committed by GitHub
parent
commit
a82e22be83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      packages/nocodb/src/lib/db/sql-client/lib/oracle/OracleClient.ts
  2. 10
      packages/nocodb/src/lib/db/sql-mgr/SqlMgr.ts
  3. 2
      packages/nocodb/src/lib/db/sql-mgr/v2/SqlMgrv2.ts
  4. 2
      packages/nocodb/src/lib/db/sql-mgr/v2/SqlMgrv2Trans.ts
  5. 7
      packages/nocodb/src/lib/db/sql-migrator/lib/KnexMigratorv2.ts
  6. 9
      packages/nocodb/src/lib/db/sql-migrator/lib/KnexMigratorv2Tans.ts
  7. 2
      packages/nocodb/src/lib/meta/NcMetaMgr.ts
  8. 2
      packages/nocodb/src/lib/utils/common/BaseApiBuilder.ts
  9. 2
      packages/nocodb/src/lib/utils/common/NcConnectionMgr.ts
  10. 2
      packages/nocodb/src/lib/utils/common/NcConnectionMgrv2.ts

2
packages/nocodb/src/lib/db/sql-client/lib/oracle/OracleClient.ts

@ -1913,7 +1913,7 @@ class OracleClient extends KnexClient {
* @returns {Number} code * @returns {Number} code
* @returns {String} message * @returns {String} message
*/ */
async totalRecords(_args: any = {}) { async totalRecords(_args: any = {}): Promise<Result> {
// @ts-ignore // @ts-ignore
const func = this.totalRecords.name; const func = this.totalRecords.name;
throw new Error('Function not supported for oracle yet'); throw new Error('Function not supported for oracle yet');

10
packages/nocodb/src/lib/db/sql-mgr/SqlMgr.ts

@ -17,6 +17,14 @@ import NcConnectionMgr from '../../utils/common/NcConnectionMgr';
import { customAlphabet } from 'nanoid'; import { customAlphabet } from 'nanoid';
import Debug from '../util/Debug'; import Debug from '../util/Debug';
import Result from '../util/Result'; import Result from '../util/Result';
import type MssqlClient from '../sql-client/lib/mssql/MssqlClient';
import type MysqlClient from '../sql-client/lib/mysql/MysqlClient';
import type OracleClient from '../sql-client/lib/oracle/OracleClient';
import type PGClient from '../sql-client/lib/pg/PgClient';
import type SnowflakeClient from '../sql-client/lib/snowflake/SnowflakeClient';
import type SqliteClient from '../sql-client/lib/sqlite/SqliteClient';
const randomID = customAlphabet('1234567890abcdefghijklmnopqrstuvwxyz_', 20); const randomID = customAlphabet('1234567890abcdefghijklmnopqrstuvwxyz_', 20);
const log = new Debug('SqlMgr'); const log = new Debug('SqlMgr');
@ -337,7 +345,7 @@ export default class SqlMgr {
* @returns * @returns
* @memberof SqlMgr * @memberof SqlMgr
*/ */
public async projectGetSqlClient(args) { public async projectGetSqlClient(args): Promise<SnowflakeClient | MysqlClient | SqliteClient | MssqlClient | OracleClient | PGClient> {
const func = this.projectGetSqlClient.name; const func = this.projectGetSqlClient.name;
log.api(`${func}:args:`, args); log.api(`${func}:args:`, args);

2
packages/nocodb/src/lib/db/sql-mgr/v2/SqlMgrv2.ts

@ -118,7 +118,7 @@ export default class SqlMgrv2 {
return sqlMigrationStatements; return sqlMigrationStatements;
} }
protected async getSqlClient(base: Base): Promise<any> { protected async getSqlClient(base: Base) {
return NcConnectionMgrv2.getSqlClient(base); return NcConnectionMgrv2.getSqlClient(base);
} }
} }

2
packages/nocodb/src/lib/db/sql-mgr/v2/SqlMgrv2Trans.ts

@ -52,7 +52,7 @@ export default class SqlMgrv2Trans extends SqlMgrv2 {
} }
} }
protected async getSqlClient(base: Base): Promise<any> { protected async getSqlClient(base: Base) {
return NcConnectionMgrv2.getSqlClient(base, this.trx); return NcConnectionMgrv2.getSqlClient(base, this.trx);
} }

7
packages/nocodb/src/lib/db/sql-migrator/lib/KnexMigratorv2.ts

@ -1,6 +1,7 @@
import fs from 'fs'; import fs from 'fs';
import path from 'path'; import path from 'path';
import { promisify } from 'util'; import { promisify } from 'util';
import { Knex } from 'knex';
import glob from 'glob'; import glob from 'glob';
import SqlClientFactory from '../../sql-client/lib/SqlClientFactory'; import SqlClientFactory from '../../sql-client/lib/SqlClientFactory';
@ -428,7 +429,7 @@ export default class KnexMigratorv2 {
// } // }
} }
protected async getSqlClient(base: Base): Promise<any> { protected async getSqlClient(base: Base) {
return NcConnectionMgrv2.getSqlClient(base); return NcConnectionMgrv2.getSqlClient(base);
} }
@ -753,7 +754,7 @@ export default class KnexMigratorv2 {
const vm = this; const vm = this;
const trx = sqlClient.knex.isTransaction const trx = sqlClient.knex.isTransaction
? sqlClient.knex ? sqlClient.knex as Knex.Transaction
: await sqlClient.knex.transaction(); : await sqlClient.knex.transaction();
try { try {
for (const query of upStatements) { for (const query of upStatements) {
@ -920,7 +921,7 @@ export default class KnexMigratorv2 {
const vm = this; const vm = this;
const trx = sqlClient.knex.isTransaction const trx = sqlClient.knex.isTransaction
? sqlClient.knex ? sqlClient.knex as Knex.Transaction
: await sqlClient.knex.transaction(); : await sqlClient.knex.transaction();
try { try {
for (const query of downStatements) { for (const query of downStatements) {

9
packages/nocodb/src/lib/db/sql-migrator/lib/KnexMigratorv2Tans.ts

@ -11,6 +11,13 @@ import Noco from '../../../Noco';
import { XKnex } from '../../sql-data-mapper'; import { XKnex } from '../../sql-data-mapper';
import NcMetaIO from '../../../meta/NcMetaIO'; import NcMetaIO from '../../../meta/NcMetaIO';
import type MssqlClient from '../../sql-client/lib/mssql/MssqlClient';
import type MysqlClient from '../../sql-client/lib/mysql/MysqlClient';
import type OracleClient from '../../sql-client/lib/oracle/OracleClient';
import type PGClient from '../../sql-client/lib/pg/PgClient';
import type SnowflakeClient from '../../sql-client/lib/snowflake/SnowflakeClient';
import type SqliteClient from '../../sql-client/lib/sqlite/SqliteClient';
export default class KnexMigratorv2Tans extends KnexMigratorv2 { export default class KnexMigratorv2Tans extends KnexMigratorv2 {
protected sqlClient: any; protected sqlClient: any;
protected ncMeta: NcMetaIO; protected ncMeta: NcMetaIO;
@ -24,7 +31,7 @@ export default class KnexMigratorv2Tans extends KnexMigratorv2 {
protected get metaDb(): XKnex { protected get metaDb(): XKnex {
return this.ncMeta.knex || Noco.ncMeta.knex; return this.ncMeta.knex || Noco.ncMeta.knex;
} }
protected async getSqlClient(base: Base): Promise<any> { protected async getSqlClient(base: Base): Promise<SnowflakeClient | MysqlClient | SqliteClient | MssqlClient | OracleClient | PGClient> {
return this.sqlClient || NcConnectionMgrv2.getSqlClient(base); return this.sqlClient || NcConnectionMgrv2.getSqlClient(base);
} }
} }

2
packages/nocodb/src/lib/meta/NcMetaMgr.ts

@ -2909,7 +2909,7 @@ export default class NcMetaMgr {
} }
} }
protected async projectGetSqlClient(args): Promise<any> { protected async projectGetSqlClient(args) {
const builder = this.getBuilder(args); const builder = this.getBuilder(args);
return builder?.getSqlClient(); return builder?.getSqlClient();
} }

2
packages/nocodb/src/lib/utils/common/BaseApiBuilder.ts

@ -187,7 +187,7 @@ export default abstract class BaseApiBuilder<T extends Noco>
return this.connectionConfig?.meta?.dbAlias; return this.connectionConfig?.meta?.dbAlias;
} }
public async getSqlClient(): Promise<any> { public async getSqlClient() {
return NcConnectionMgr.getSqlClient({ return NcConnectionMgr.getSqlClient({
dbAlias: this.dbAlias, dbAlias: this.dbAlias,
env: this.config.env, env: this.config.env,

2
packages/nocodb/src/lib/utils/common/NcConnectionMgr.ts

@ -149,7 +149,7 @@ export default class NcConnectionMgr {
env: string; env: string;
config: NcConfig; config: NcConfig;
projectId: string; projectId: string;
}): Promise<any> { }) {
const knex = this.get({ const knex = this.get({
dbAlias, dbAlias,
env, env,

2
packages/nocodb/src/lib/utils/common/NcConnectionMgrv2.ts

@ -149,7 +149,7 @@ export default class NcConnectionMgrv2 {
// return config?.envs?.[env]?.db?.find(db => db?.meta?.dbAlias === dbAlias); // return config?.envs?.[env]?.db?.find(db => db?.meta?.dbAlias === dbAlias);
// } // }
public static async getSqlClient(base: Base, _knex = null): Promise<any> { public static async getSqlClient(base: Base, _knex = null) {
const knex = _knex || this.get(base); const knex = _knex || this.get(base);
return SqlClientFactory.create({ return SqlClientFactory.create({
knex, knex,

Loading…
Cancel
Save