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