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.
191 lines
3.7 KiB
191 lines
3.7 KiB
2 years ago
|
import { ClientType } from '~/lib'
|
||
2 years ago
|
|
||
|
export interface ProjectCreateForm {
|
||
|
title: string
|
||
|
dataSource: {
|
||
|
client: ClientType
|
||
2 years ago
|
connection: DefaultConnection | SQLiteConnection
|
||
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
|
export interface DefaultConnection {
|
||
|
host: string
|
||
|
database: string
|
||
|
user: string
|
||
|
password: string
|
||
|
port: number | string
|
||
|
ssl?: Record<CertTypes, string> | 'true'
|
||
|
}
|
||
|
|
||
|
export interface SQLiteConnection {
|
||
|
client: ClientType.SQLITE
|
||
|
database: string
|
||
|
connection: {
|
||
|
filename?: string
|
||
|
}
|
||
|
useNullAsDefault?: boolean
|
||
|
}
|
||
|
|
||
2 years ago
|
const defaultHost = 'localhost'
|
||
2 years ago
|
|
||
2 years ago
|
const testDataBaseNames = {
|
||
2 years ago
|
[ClientType.MYSQL]: null,
|
||
2 years ago
|
mysql: null,
|
||
2 years ago
|
[ClientType.PG]: 'postgres',
|
||
2 years ago
|
oracledb: 'xe',
|
||
2 years ago
|
[ClientType.MSSQL]: undefined,
|
||
|
[ClientType.SQLITE]: 'a.sqlite',
|
||
2 years ago
|
}
|
||
|
|
||
|
export const getTestDatabaseName = (db: { client: ClientType; connection?: { database?: string } }) => {
|
||
2 years ago
|
if (db.client === ClientType.PG) return db.connection?.database
|
||
2 years ago
|
return testDataBaseNames[db.client as keyof typeof testDataBaseNames]
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
export const clientTypes = [
|
||
|
{
|
||
|
text: 'MySql',
|
||
2 years ago
|
value: ClientType.MYSQL,
|
||
2 years ago
|
},
|
||
|
{
|
||
|
text: 'MSSQL',
|
||
2 years ago
|
value: ClientType.MSSQL,
|
||
2 years ago
|
},
|
||
|
{
|
||
|
text: 'PostgreSQL',
|
||
2 years ago
|
value: ClientType.PG,
|
||
2 years ago
|
},
|
||
|
{
|
||
|
text: 'SQLite',
|
||
2 years ago
|
value: ClientType.SQLITE,
|
||
2 years ago
|
},
|
||
2 years ago
|
]
|
||
|
|
||
|
const homeDir = ''
|
||
2 years ago
|
|
||
|
type ConnectionClientType =
|
||
|
| Exclude<ClientType, ClientType.SQLITE>
|
||
|
| 'tidb'
|
||
|
| 'yugabyte'
|
||
|
| 'citusdb'
|
||
|
| 'cockroachdb'
|
||
|
| 'oracledb'
|
||
|
| 'greenplum'
|
||
|
|
||
|
const sampleConnectionData: { [key in ConnectionClientType]: DefaultConnection } & { [ClientType.SQLITE]: SQLiteConnection } = {
|
||
2 years ago
|
[ClientType.PG]: {
|
||
|
host: defaultHost,
|
||
2 years ago
|
port: '5432',
|
||
|
user: 'postgres',
|
||
|
password: 'password',
|
||
|
database: '_test',
|
||
2 years ago
|
},
|
||
2 years ago
|
[ClientType.MYSQL]: {
|
||
|
host: defaultHost,
|
||
2 years ago
|
port: '3306',
|
||
|
user: 'root',
|
||
|
password: 'password',
|
||
|
database: '_test',
|
||
2 years ago
|
},
|
||
2 years ago
|
[ClientType.VITESS]: {
|
||
|
host: defaultHost,
|
||
2 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
|
tidb: {
|
||
2 years ago
|
host: defaultHost,
|
||
2 years ago
|
port: '4000',
|
||
|
user: 'root',
|
||
|
password: '',
|
||
|
database: '_test',
|
||
2 years ago
|
},
|
||
2 years ago
|
yugabyte: {
|
||
2 years ago
|
host: defaultHost,
|
||
2 years ago
|
port: '5432',
|
||
|
user: 'postgres',
|
||
|
password: '',
|
||
|
database: '_test',
|
||
2 years ago
|
},
|
||
2 years ago
|
citusdb: {
|
||
2 years ago
|
host: defaultHost,
|
||
2 years ago
|
port: '5432',
|
||
|
user: 'postgres',
|
||
|
password: '',
|
||
|
database: '_test',
|
||
2 years ago
|
},
|
||
2 years ago
|
cockroachdb: {
|
||
2 years ago
|
host: defaultHost,
|
||
2 years ago
|
port: '5432',
|
||
|
user: 'postgres',
|
||
|
password: '',
|
||
|
database: '_test',
|
||
2 years ago
|
},
|
||
2 years ago
|
greenplum: {
|
||
2 years ago
|
host: defaultHost,
|
||
2 years ago
|
port: '5432',
|
||
|
user: 'postgres',
|
||
|
password: '',
|
||
|
database: '_test',
|
||
2 years ago
|
},
|
||
2 years ago
|
oracledb: {
|
||
2 years ago
|
host: defaultHost,
|
||
2 years ago
|
port: '1521',
|
||
|
user: 'system',
|
||
|
password: 'Oracle18',
|
||
|
database: '_test',
|
||
2 years ago
|
},
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
export const getDefaultConnectionConfig = (client: ClientType): ProjectCreateForm['dataSource'] => {
|
||
2 years ago
|
return {
|
||
|
client,
|
||
|
connection: sampleConnectionData[client],
|
||
2 years ago
|
searchPath: [ClientType.PG, ClientType.MSSQL].includes(client)
|
||
|
? client === ClientType.PG
|
||
|
? ['public']
|
||
|
: ['dbo']
|
||
|
: undefined,
|
||
2 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',
|
||
|
}
|
||
|
|
||
2 years ago
|
export { SSLUsage, CertTypes }
|