mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
219 lines
4.4 KiB
219 lines
4.4 KiB
1 year ago
|
import { ClientType } from '../lib'
|
||
|
|
||
|
// todo: move to noco-sdk
|
||
|
export enum NcProjectType {
|
||
|
DB = 'database',
|
||
|
}
|
||
2 years ago
|
|
||
2 years ago
|
interface ProjectCreateForm {
|
||
2 years ago
|
title: string
|
||
|
dataSource: {
|
||
|
client: ClientType
|
||
2 years ago
|
connection: DefaultConnection | SQLiteConnection | SnowflakeConnection
|
||
2 years ago
|
searchPath?: string[]
|
||
2 years ago
|
}
|
||
|
inflection: {
|
||
|
inflectionColumn?: string
|
||
|
inflectionTable?: string
|
||
|
}
|
||
2 years ago
|
sslUse?: SSLUsage
|
||
2 years ago
|
extraParameters: { key: string; value: string }[]
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
interface DefaultConnection {
|
||
2 years ago
|
host: string
|
||
|
database: string
|
||
|
user: string
|
||
|
password: string
|
||
|
port: number | string
|
||
2 years ago
|
ssl?: Record<CertTypes, string> | 'no-verify' | 'true'
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
interface SQLiteConnection {
|
||
2 years ago
|
client: ClientType.SQLITE
|
||
|
database: string
|
||
|
connection: {
|
||
|
filename?: string
|
||
|
}
|
||
|
useNullAsDefault?: boolean
|
||
|
}
|
||
|
|
||
1 year ago
|
interface SnowflakeConnection {
|
||
2 years ago
|
account: string
|
||
|
username: string
|
||
|
password: string
|
||
|
warehouse: string
|
||
2 years ago
|
database: string
|
||
|
schema: string
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
const defaultHost = 'localhost'
|
||
2 years ago
|
|
||
3 years ago
|
const testDataBaseNames = {
|
||
2 years ago
|
[ClientType.MYSQL]: null,
|
||
3 years ago
|
mysql: null,
|
||
2 years ago
|
[ClientType.PG]: 'postgres',
|
||
3 years ago
|
oracledb: 'xe',
|
||
2 years ago
|
[ClientType.MSSQL]: undefined,
|
||
|
[ClientType.SQLITE]: 'a.sqlite',
|
||
3 years ago
|
}
|
||
|
|
||
|
export const getTestDatabaseName = (db: { client: ClientType; connection?: { database?: string } }) => {
|
||
2 years ago
|
if (db.client === ClientType.PG || db.client === ClientType.SNOWFLAKE) return db.connection?.database
|
||
3 years ago
|
return testDataBaseNames[db.client as keyof typeof testDataBaseNames]
|
||
3 years ago
|
}
|
||
|
|
||
3 years ago
|
export const clientTypes = [
|
||
|
{
|
||
|
text: 'MySql',
|
||
2 years ago
|
value: ClientType.MYSQL,
|
||
3 years ago
|
},
|
||
|
{
|
||
|
text: 'MSSQL',
|
||
2 years ago
|
value: ClientType.MSSQL,
|
||
3 years ago
|
},
|
||
|
{
|
||
|
text: 'PostgreSQL',
|
||
2 years ago
|
value: ClientType.PG,
|
||
3 years ago
|
},
|
||
|
{
|
||
|
text: 'SQLite',
|
||
2 years ago
|
value: ClientType.SQLITE,
|
||
3 years ago
|
},
|
||
2 years ago
|
{
|
||
1 year ago
|
text: 'Snowflake',
|
||
2 years ago
|
value: ClientType.SNOWFLAKE,
|
||
|
},
|
||
3 years ago
|
]
|
||
|
|
||
|
const homeDir = ''
|
||
2 years ago
|
|
||
|
type ConnectionClientType =
|
||
2 years ago
|
| Exclude<ClientType, ClientType.SQLITE | ClientType.SNOWFLAKE>
|
||
2 years ago
|
| 'tidb'
|
||
|
| 'yugabyte'
|
||
|
| 'citusdb'
|
||
|
| 'cockroachdb'
|
||
|
| 'oracledb'
|
||
|
| 'greenplum'
|
||
|
|
||
2 years ago
|
const sampleConnectionData: { [key in ConnectionClientType]: DefaultConnection } & { [ClientType.SQLITE]: SQLiteConnection } & {
|
||
|
[ClientType.SNOWFLAKE]: SnowflakeConnection
|
||
|
} = {
|
||
2 years ago
|
[ClientType.PG]: {
|
||
|
host: defaultHost,
|
||
3 years ago
|
port: '5432',
|
||
|
user: 'postgres',
|
||
|
password: 'password',
|
||
|
database: '_test',
|
||
2 years ago
|
},
|
||
2 years ago
|
[ClientType.MYSQL]: {
|
||
|
host: defaultHost,
|
||
3 years ago
|
port: '3306',
|
||
|
user: 'root',
|
||
|
password: 'password',
|
||
|
database: '_test',
|
||
2 years ago
|
},
|
||
2 years ago
|
[ClientType.VITESS]: {
|
||
|
host: defaultHost,
|
||
3 years ago
|
port: '15306',
|
||
|
user: 'root',
|
||
|
password: 'password',
|
||
|
database: '_test',
|
||
2 years ago
|
},
|
||
2 years ago
|
[ClientType.MSSQL]: {
|
||
|
host: defaultHost,
|
||
|
port: 1433,
|
||
|
user: 'sa',
|
||
|
password: 'Password123.',
|
||
|
database: '_test',
|
||
2 years ago
|
},
|
||
2 years ago
|
[ClientType.SQLITE]: {
|
||
|
client: ClientType.SQLITE,
|
||
|
database: homeDir,
|
||
|
connection: {
|
||
|
filename: homeDir,
|
||
|
},
|
||
|
useNullAsDefault: true,
|
||
|
},
|
||
2 years ago
|
[ClientType.SNOWFLAKE]: {
|
||
|
account: 'account',
|
||
|
username: 'username',
|
||
|
password: 'password',
|
||
|
warehouse: 'warehouse',
|
||
|
database: 'database',
|
||
|
schema: 'schema',
|
||
|
},
|
||
3 years ago
|
tidb: {
|
||
2 years ago
|
host: defaultHost,
|
||
3 years ago
|
port: '4000',
|
||
|
user: 'root',
|
||
|
password: '',
|
||
|
database: '_test',
|
||
2 years ago
|
},
|
||
3 years ago
|
yugabyte: {
|
||
2 years ago
|
host: defaultHost,
|
||
3 years ago
|
port: '5432',
|
||
|
user: 'postgres',
|
||
|
password: '',
|
||
|
database: '_test',
|
||
2 years ago
|
},
|
||
3 years ago
|
citusdb: {
|
||
2 years ago
|
host: defaultHost,
|
||
3 years ago
|
port: '5432',
|
||
|
user: 'postgres',
|
||
|
password: '',
|
||
|
database: '_test',
|
||
2 years ago
|
},
|
||
3 years ago
|
cockroachdb: {
|
||
2 years ago
|
host: defaultHost,
|
||
3 years ago
|
port: '5432',
|
||
|
user: 'postgres',
|
||
|
password: '',
|
||
|
database: '_test',
|
||
2 years ago
|
},
|
||
3 years ago
|
greenplum: {
|
||
2 years ago
|
host: defaultHost,
|
||
3 years ago
|
port: '5432',
|
||
|
user: 'postgres',
|
||
|
password: '',
|
||
|
database: '_test',
|
||
2 years ago
|
},
|
||
3 years ago
|
oracledb: {
|
||
2 years ago
|
host: defaultHost,
|
||
3 years ago
|
port: '1521',
|
||
|
user: 'system',
|
||
|
password: 'Oracle18',
|
||
|
database: '_test',
|
||
2 years ago
|
},
|
||
3 years ago
|
}
|
||
|
|
||
2 years ago
|
export const getDefaultConnectionConfig = (client: ClientType): ProjectCreateForm['dataSource'] => {
|
||
3 years ago
|
return {
|
||
|
client,
|
||
|
connection: sampleConnectionData[client],
|
||
2 years ago
|
searchPath: [ClientType.PG, ClientType.MSSQL].includes(client)
|
||
|
? client === ClientType.PG
|
||
|
? ['public']
|
||
|
: ['dbo']
|
||
|
: undefined,
|
||
3 years ago
|
}
|
||
|
}
|
||
2 years ago
|
|
||
2 years ago
|
enum SSLUsage {
|
||
2 years ago
|
No = 'No',
|
||
|
Allowed = 'Allowed',
|
||
|
Preferred = 'Preferred',
|
||
|
Required = 'Required',
|
||
|
RequiredWithCa = 'Required-CA',
|
||
|
RequiredWithIdentity = 'Required-Identity',
|
||
|
}
|
||
|
|
||
2 years ago
|
enum CertTypes {
|
||
2 years ago
|
ca = 'ca',
|
||
|
cert = 'cert',
|
||
|
key = 'key',
|
||
|
}
|
||
|
|
||
1 year ago
|
export { SSLUsage, CertTypes, ProjectCreateForm, DefaultConnection, SQLiteConnection, SnowflakeConnection }
|