|
|
|
@ -1,43 +1,75 @@
|
|
|
|
|
import { adjectives, animals, starWars, uniqueNamesGenerator } from 'unique-names-generator' |
|
|
|
|
import type { ClientType, ProjectCreateForm } from '~/lib/types' |
|
|
|
|
import { ClientType } from '~/lib/enums' |
|
|
|
|
|
|
|
|
|
export interface ProjectCreateForm { |
|
|
|
|
title: string |
|
|
|
|
dataSource: { |
|
|
|
|
client: ClientType |
|
|
|
|
connection: |
|
|
|
|
| { |
|
|
|
|
host: string |
|
|
|
|
database: string |
|
|
|
|
user: string |
|
|
|
|
password: string |
|
|
|
|
port: number | string |
|
|
|
|
ssl?: Record<string, string> |
|
|
|
|
searchPath?: string[] |
|
|
|
|
} |
|
|
|
|
| { |
|
|
|
|
client?: ClientType.SQLITE |
|
|
|
|
database: string |
|
|
|
|
connection?: { |
|
|
|
|
filename?: string |
|
|
|
|
} |
|
|
|
|
useNullAsDefault?: boolean |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
inflection: { |
|
|
|
|
inflectionColumn?: string |
|
|
|
|
inflectionTable?: string |
|
|
|
|
} |
|
|
|
|
sslUse?: any |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const defaultHost = 'localhost' |
|
|
|
|
|
|
|
|
|
const testDataBaseNames = { |
|
|
|
|
mysql2: null, |
|
|
|
|
[ClientType.MYSQL]: null, |
|
|
|
|
mysql: null, |
|
|
|
|
pg: 'postgres', |
|
|
|
|
[ClientType.PG]: 'postgres', |
|
|
|
|
oracledb: 'xe', |
|
|
|
|
mssql: undefined, |
|
|
|
|
sqlite3: 'a.sqlite', |
|
|
|
|
[ClientType.MSSQL]: undefined, |
|
|
|
|
[ClientType.SQLITE]: 'a.sqlite', |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export const getTestDatabaseName = (db: { client: ClientType; connection?: { database?: string } }) => { |
|
|
|
|
if (db.client === 'pg') return db.connection?.database |
|
|
|
|
if (db.client === ClientType.PG) return db.connection?.database |
|
|
|
|
return testDataBaseNames[db.client as keyof typeof testDataBaseNames] |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export const clientTypes = [ |
|
|
|
|
{ |
|
|
|
|
text: 'MySql', |
|
|
|
|
value: 'mysql2', |
|
|
|
|
value: ClientType.MYSQL, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
text: 'MSSQL', |
|
|
|
|
value: 'mssql', |
|
|
|
|
value: ClientType.MSSQL, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
text: 'PostgreSQL', |
|
|
|
|
value: 'pg', |
|
|
|
|
value: ClientType.PG, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
text: 'SQLite', |
|
|
|
|
value: 'sqlite3', |
|
|
|
|
value: ClientType.SQLITE, |
|
|
|
|
}, |
|
|
|
|
] |
|
|
|
|
|
|
|
|
|
const homeDir = '' |
|
|
|
|
const sampleConnectionData: Record<ClientType | string, ProjectCreateForm['dataSource']['connection']> = { |
|
|
|
|
pg: { |
|
|
|
|
host: 'localhost', |
|
|
|
|
[ClientType.PG]: { |
|
|
|
|
host: defaultHost, |
|
|
|
|
port: '5432', |
|
|
|
|
user: 'postgres', |
|
|
|
|
password: 'password', |
|
|
|
@ -49,8 +81,8 @@ const sampleConnectionData: Record<ClientType | string, ProjectCreateForm['dataS
|
|
|
|
|
cert: '', |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
mysql2: { |
|
|
|
|
host: 'localhost', |
|
|
|
|
[ClientType.MYSQL]: { |
|
|
|
|
host: defaultHost, |
|
|
|
|
port: '3306', |
|
|
|
|
user: 'root', |
|
|
|
|
password: 'password', |
|
|
|
@ -61,8 +93,8 @@ const sampleConnectionData: Record<ClientType | string, ProjectCreateForm['dataS
|
|
|
|
|
cert: '', |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
vitess: { |
|
|
|
|
host: 'localhost', |
|
|
|
|
[ClientType.VITESS]: { |
|
|
|
|
host: defaultHost, |
|
|
|
|
port: '15306', |
|
|
|
|
user: 'root', |
|
|
|
|
password: 'password', |
|
|
|
@ -73,8 +105,29 @@ const sampleConnectionData: Record<ClientType | string, ProjectCreateForm['dataS
|
|
|
|
|
cert: '', |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
[ClientType.MSSQL]: { |
|
|
|
|
host: defaultHost, |
|
|
|
|
port: 1433, |
|
|
|
|
user: 'sa', |
|
|
|
|
password: 'Password123.', |
|
|
|
|
database: '_test', |
|
|
|
|
searchPath: ['dbo'], |
|
|
|
|
ssl: { |
|
|
|
|
ca: '', |
|
|
|
|
key: '', |
|
|
|
|
cert: '', |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
[ClientType.SQLITE]: { |
|
|
|
|
client: ClientType.SQLITE, |
|
|
|
|
database: homeDir, |
|
|
|
|
connection: { |
|
|
|
|
filename: homeDir, |
|
|
|
|
}, |
|
|
|
|
useNullAsDefault: true, |
|
|
|
|
}, |
|
|
|
|
tidb: { |
|
|
|
|
host: 'localhost', |
|
|
|
|
host: defaultHost, |
|
|
|
|
port: '4000', |
|
|
|
|
user: 'root', |
|
|
|
|
password: '', |
|
|
|
@ -86,7 +139,7 @@ const sampleConnectionData: Record<ClientType | string, ProjectCreateForm['dataS
|
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
yugabyte: { |
|
|
|
|
host: 'localhost', |
|
|
|
|
host: defaultHost, |
|
|
|
|
port: '5432', |
|
|
|
|
user: 'postgres', |
|
|
|
|
password: '', |
|
|
|
@ -98,7 +151,7 @@ const sampleConnectionData: Record<ClientType | string, ProjectCreateForm['dataS
|
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
citusdb: { |
|
|
|
|
host: 'localhost', |
|
|
|
|
host: defaultHost, |
|
|
|
|
port: '5432', |
|
|
|
|
user: 'postgres', |
|
|
|
|
password: '', |
|
|
|
@ -110,7 +163,7 @@ const sampleConnectionData: Record<ClientType | string, ProjectCreateForm['dataS
|
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
cockroachdb: { |
|
|
|
|
host: 'localhost', |
|
|
|
|
host: defaultHost, |
|
|
|
|
port: '5432', |
|
|
|
|
user: 'postgres', |
|
|
|
|
password: '', |
|
|
|
@ -122,7 +175,7 @@ const sampleConnectionData: Record<ClientType | string, ProjectCreateForm['dataS
|
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
greenplum: { |
|
|
|
|
host: 'localhost', |
|
|
|
|
host: defaultHost, |
|
|
|
|
port: '5432', |
|
|
|
|
user: 'postgres', |
|
|
|
|
password: '', |
|
|
|
@ -133,21 +186,8 @@ const sampleConnectionData: Record<ClientType | string, ProjectCreateForm['dataS
|
|
|
|
|
cert: '', |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
mssql: { |
|
|
|
|
host: 'localhost', |
|
|
|
|
port: 1433, |
|
|
|
|
user: 'sa', |
|
|
|
|
password: 'Password123.', |
|
|
|
|
database: '_test', |
|
|
|
|
searchPath: ['dbo'], |
|
|
|
|
ssl: { |
|
|
|
|
ca: '', |
|
|
|
|
key: '', |
|
|
|
|
cert: '', |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
oracledb: { |
|
|
|
|
host: 'localhost', |
|
|
|
|
host: defaultHost, |
|
|
|
|
port: '1521', |
|
|
|
|
user: 'system', |
|
|
|
|
password: 'Oracle18', |
|
|
|
@ -158,14 +198,6 @@ const sampleConnectionData: Record<ClientType | string, ProjectCreateForm['dataS
|
|
|
|
|
cert: '', |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
sqlite3: { |
|
|
|
|
client: 'sqlite3', |
|
|
|
|
database: homeDir, |
|
|
|
|
connection: { |
|
|
|
|
filename: homeDir, |
|
|
|
|
}, |
|
|
|
|
useNullAsDefault: true, |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export const getDefaultConnectionConfig = (client: ClientType): ProjectCreateForm['dataSource'] => { |
|
|
|
|