Skip to content

Commit

Permalink
fix: type issues with SqlClient
Browse files Browse the repository at this point in the history
Signed-off-by: mertmit <mertmit99@gmail.com>
  • Loading branch information
mertmit committed Mar 26, 2024
1 parent 6b6ef4f commit 67895f5
Show file tree
Hide file tree
Showing 20 changed files with 91 additions and 2,678 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import type { SourceType } from 'nocodb-sdk'
import { Form, message } from 'ant-design-vue'
import type { SelectHandler } from 'ant-design-vue/es/vc-select/Select'
import type { DefaultConnection, ProjectCreateForm, SQLiteConnection } from '#imports'
import type { DefaultConnection, ProjectCreateForm, SQLiteConnection, SnowflakeConnection } from '#imports'
import {
CertTypes,
ClientType,
Expand Down Expand Up @@ -387,6 +387,56 @@ onMounted(async () => {
<a-input v-model:value="(formState.dataSource.connection as SQLiteConnection).connection.filename" />
</a-form-item>

<template v-else-if="formState.dataSource.client === ClientType.SNOWFLAKE">
<!-- Account -->
<a-form-item :label="$t('labels.account')" v-bind="validateInfos['dataSource.connection.account']">
<a-input
v-model:value="(formState.dataSource.connection as SnowflakeConnection).account"
class="nc-extdb-host-address"
/>
</a-form-item>

<!-- Username -->
<a-form-item :label="$t('labels.username')" v-bind="validateInfos['dataSource.connection.username']">
<a-input
v-model:value="(formState.dataSource.connection as SnowflakeConnection).username"
class="nc-extdb-host-user"
/>
</a-form-item>

<!-- Password -->
<a-form-item :label="$t('labels.password')" v-bind="validateInfos['dataSource.connection.password']">
<a-input-password
v-model:value="(formState.dataSource.connection as SnowflakeConnection).password"
class="nc-extdb-host-password"
/>
</a-form-item>

<!-- Warehouse -->
<a-form-item label="Warehouse" v-bind="validateInfos['dataSource.connection.warehouse']">
<a-input
v-model:value="(formState.dataSource.connection as SnowflakeConnection).warehouse"
class="nc-extdb-host-database"
/>
</a-form-item>

<!-- Database -->
<a-form-item :label="$t('labels.database')" v-bind="validateInfos['dataSource.connection.database']">
<a-input
v-model:value="(formState.dataSource.connection as SnowflakeConnection).database"
class="nc-extdb-host-database"
/>
</a-form-item>

<!-- Schema -->
<a-form-item label="Schema" v-bind="validateInfos['dataSource.connection.schema']">
<a-input
v-model:value="(formState.dataSource.connection as SnowflakeConnection).schema"
class="nc-extdb-host-database"
/>
</a-form-item>
</template>

<template v-else>
<!-- Host Address -->
<a-form-item :label="$t('labels.hostAddress')" v-bind="validateInfos['dataSource.connection.host']">
Expand Down
7 changes: 5 additions & 2 deletions packages/nc-gui/components/dlg/TableCreate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const inputEl = ref<HTMLInputElement>()
const { addTab } = useTabs()
const { isMysql, isMssql, isPg } = useBase()
const { isMysql, isMssql, isPg, isSnowflake } = useBase()
const { loadProjectTables, addTable } = useTablesStore()
Expand Down Expand Up @@ -145,7 +145,7 @@ onMounted(() => {
</template>
<div class="flex flex-col mt-2">
<a-form :model="table" name="create-new-table-form" @keydown.enter="_createTable" @keydown.esc="dialogShow = false">
<a-form-item v-bind="validateInfos.title">
<a-form-item v-bind="validateInfos.title" :class="{ '!mb-1': isSnowflake(props.sourceId) }">
<a-input
ref="inputEl"
v-model:value="table.title"
Expand All @@ -155,6 +155,9 @@ onMounted(() => {
:placeholder="$t('msg.info.enterTableName')"
/>
</a-form-item>
<template v-if="isSnowflake(props.sourceId)">
<a-checkbox v-model:checked="table.is_hybrid" class="!flex flex-row items-center"> Hybrid Table </a-checkbox>
</template>
<div class="nc-table-advanced-options" :class="{ active: isAdvanceOptVisible }">
<div>
<div class="mb-1">
Expand Down
3 changes: 2 additions & 1 deletion packages/nc-gui/composables/useTableNew.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ import {
} from '#imports'

export function useTableNew(param: { onTableCreate?: (tableMeta: TableType) => void; baseId: string; sourceId?: string }) {
const table = reactive<{ title: string; table_name: string; columns: string[] }>({
const table = reactive<{ title: string; table_name: string; columns: string[]; is_hybrid: boolean }>({
title: '',
table_name: '',
columns: SYSTEM_COLUMNS,
is_hybrid: true,
})

const { t } = useI18n()
Expand Down
5 changes: 5 additions & 0 deletions packages/nc-gui/store/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ export const useBase = defineStore('baseStore', () => {
return getBaseType(sourceId) === 'pg'
}

function isSnowflake(sourceId?: string) {
return getBaseType(sourceId) === 'snowflake'
}

function isXcdbBase(sourceId?: string) {
const source = sources.value.find((source) => source.id === sourceId)
return (source?.is_meta as boolean) || (source?.is_local as boolean) || false
Expand Down Expand Up @@ -284,6 +288,7 @@ export const useBase = defineStore('baseStore', () => {
isMssql,
isPg,
isSqlite,
isSnowflake,
sqlUis,
isSharedBase,
isSharedErd,
Expand Down
12 changes: 6 additions & 6 deletions packages/nc-gui/utils/baseCreateUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,12 @@ const sampleConnectionData: { [key in ConnectionClientType]: DefaultConnection }
useNullAsDefault: true,
},
[ClientType.SNOWFLAKE]: {
account: 'account',
username: 'username',
password: 'password',
warehouse: 'warehouse',
database: 'database',
schema: 'schema',
account: 'LOCATOR.REGION',
username: 'USERNAME',
password: 'PASSWORD',
warehouse: 'COMPUTE_WH',
database: 'DATABASE',
schema: 'PUBLIC',
},
tidb: {
host: defaultHost,
Expand Down
4 changes: 2 additions & 2 deletions packages/nocodb-sdk/src/lib/Api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11100,7 +11100,7 @@ export class Api<
* @tags DB Data Table Row
* @name Update
* @summary Update Table Rows
* @request PUT:/api/v2/tables/{tableId}/records
* @request PATCH:/api/v2/tables/{tableId}/records
* @response `200` `any` OK
* @response `400` `{
\** @example BadRequest [Error]: <ERROR MESSAGE> *\
Expand All @@ -11125,7 +11125,7 @@ export class Api<
}
>({
path: `/api/v2/tables/${tableId}/records`,
method: 'PUT',
method: 'PATCH',
query: query,
body: data,
type: ContentType.Json,
Expand Down
1 change: 1 addition & 0 deletions packages/nocodb/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@ test_sakila_?.db
# nc-gui dir is copied for building local docker.
/docker/main.js
/docker/nc-gui/
/docker/public/

/tests/unit/.env
3 changes: 0 additions & 3 deletions packages/nocodb/src/db/CustomKnex.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Knex, knex } from 'knex';
import { SnowflakeClient } from 'nc-help';
import { defaults, types } from 'pg';
import dayjs from 'dayjs';
import type { FilterType } from 'nocodb-sdk';
Expand Down Expand Up @@ -1029,8 +1028,6 @@ function CustomKnex(
arg.useNullAsDefault = true;
}

if (arg?.client === 'snowflake') arg.client = SnowflakeClient;

const kn: any = knex(arg);

const knexRaw = kn.raw;
Expand Down
6 changes: 5 additions & 1 deletion packages/nocodb/src/db/sql-client/lib/SqlClient.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
class SqlClient {
protected connectionConfig: any;
protected sqlClient: any;
protected queries: any;
protected _version: any;

constructor(connectionConfig) {
this.connectionConfig = connectionConfig;
Expand Down Expand Up @@ -108,7 +110,9 @@ class SqlClient {

async tableSelectStatement(_args): Promise<any> {}

async totalRecords(_args): Promise<any> {}
async totalRecords(_args?): Promise<any> {}

async getDefaultByteaOutputFormat(_args = {}): Promise<any> {}
}

export default SqlClient;
5 changes: 0 additions & 5 deletions packages/nocodb/src/db/sql-client/lib/SqlClientFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,6 @@ export default class {
}
}

// todo: tobe done
// if (Noco.isEE()) {
// return SqlClientFactoryEE.create(connectionConfig);
// }

return SqlClientFactory.create(connectionConfig);
}
}
2 changes: 0 additions & 2 deletions packages/nocodb/src/db/sql-client/lib/mysql/MysqlClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ const log = new Debug('MysqlClient');
const evt = new Emit();

class MysqlClient extends KnexClient {
protected queries: any;
protected _version: any;
protected types: any;

constructor(connectionConfig) {
Expand Down
2 changes: 0 additions & 2 deletions packages/nocodb/src/db/sql-client/lib/pg/PgClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import queries from '~/db/sql-client/lib/pg/pg.queries';
const log = new Debug('PGClient');

class PGClient extends KnexClient {
protected queries: any;
protected _version: any;
constructor(connectionConfig) {
super(connectionConfig);
// this.sqlClient = null;
Expand Down

1 comment on commit 67895f5

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR changes have been deployed. Please run the following command to verify:

docker run -d -p 8888:8080 nocodb/nocodb-timely:0.204.9-pr-7970-20240326-0843

Please sign in to comment.