Skip to content

Commit 75751f2

Browse files
feat(schema): adds table schema & query copy (#275)
Co-authored-by: Valerii Strilets <valerii.strilets@gmail.com>
1 parent 9994c12 commit 75751f2

37 files changed

Lines changed: 1711 additions & 74 deletions

File tree

apps/desktop/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
"arktype": "catalog:",
8282
"babel-plugin-react-compiler": "catalog:",
8383
"better-auth": "catalog:",
84+
"change-case": "catalog:",
8485
"date-fns": "catalog:",
8586
"drizzle-kit": "catalog:",
8687
"drizzle-orm": "catalog:",

apps/desktop/src/components/sidebar-link.tsx

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,29 @@ import type { ComponentProps } from 'react'
33
import { cn } from '@conar/ui/lib/utils'
44
import { Link } from '@tanstack/react-router'
55

6+
const baseClasses = 'flex w-full items-center gap-2 rounded-md border px-2 py-1 text-sm'
7+
const activeClasses = 'border-primary/20 bg-primary/10 text-primary hover:bg-primary/20'
8+
const inactiveClasses = 'border-transparent text-foreground hover:bg-accent/30'
9+
10+
export function SidebarButton({ className, active, ...props }: ComponentProps<'button'> & { active?: boolean }) {
11+
return (
12+
<button
13+
type="button"
14+
className={cn(baseClasses, className, active ? activeClasses : inactiveClasses)}
15+
{...props}
16+
/>
17+
)
18+
}
19+
620
export function SidebarLink({
721
className,
822
...props
923
}: LinkProps & Omit<ComponentProps<'a'>, 'children'>) {
1024
return (
1125
<Link
12-
activeProps={{ className: 'border-primary/20 bg-primary/10 text-primary hover:bg-primary/20' }}
13-
inactiveProps={{ className: 'border-transparent text-foreground hover:bg-accent/30' }}
14-
className={cn(`
15-
flex w-full items-center gap-2 rounded-md border px-2 py-1 text-sm
16-
`, className)}
26+
activeProps={{ className: activeClasses }}
27+
inactiveProps={{ className: inactiveClasses }}
28+
className={cn(baseClasses, className)}
1729
{...props}
1830
/>
1931
)

apps/desktop/src/entities/connection/components/table/table-cell-table.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ export function TableCellTable({ schema, table, column, value }: { schema: strin
6666
header: props => (
6767
<TableHeaderCell
6868
column={column}
69-
resize={false}
7069
{...props}
7170
/>
7271
),

apps/desktop/src/entities/connection/components/table/utils.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,31 @@
11
export interface Column {
22
id: string
3-
type?: string
3+
type: string
4+
label?: string
45
enum?: string
56
isArray?: boolean
67
isEditable?: boolean
78
isNullable?: boolean
9+
maxLength?: number | null
10+
precision?: number | null
11+
scale?: number | null
812
unique?: string
913
primaryKey?: string
14+
defaultValue?: string | null
1015
foreign?: {
1116
name: string
1217
schema: string
1318
table: string
1419
column: string
20+
onDelete?: string
21+
onUpdate?: string
1522
}
1623
references?: {
1724
name: string
1825
schema: string
1926
table: string
2027
column: string
28+
isUnique?: boolean
2129
}[]
2230
}
2331

apps/desktop/src/entities/connection/dialects/clickhouse/index.ts

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { CompiledQuery, Dialect, Driver, QueryResult } from 'kysely'
22
import type { connections } from '~/drizzle'
33
import { type } from 'arktype'
4-
import { MysqlQueryCompiler } from 'kysely'
4+
import { DummyDriver, MysqlQueryCompiler } from 'kysely'
55
import { logSql } from '../../sql'
66

77
function escapeSqlString(v: string) {
@@ -86,19 +86,34 @@ function createDriver(connection: typeof connections.$inferSelect) {
8686
} satisfies Driver
8787
}
8888

89+
function clickhouseAdapter() {
90+
return {
91+
supportsCreateIfNotExists: false,
92+
supportsTransactionalDdl: false,
93+
supportsReturning: false,
94+
acquireMigrationLock: async () => {},
95+
releaseMigrationLock: async () => {},
96+
}
97+
}
98+
8999
export function clickhouseDialect(connection: typeof connections.$inferSelect) {
90100
return {
91-
createAdapter: () => ({
92-
supportsCreateIfNotExists: false,
93-
supportsTransactionalDdl: false,
94-
supportsReturning: false,
95-
acquireMigrationLock: async () => {},
96-
releaseMigrationLock: async () => {},
97-
}),
101+
createAdapter: clickhouseAdapter,
98102
createDriver: () => createDriver(connection),
99103
createQueryCompiler: () => new MysqlQueryCompiler(),
100104
createIntrospector: () => {
101105
throw new Error('Not implemented')
102106
},
103107
} satisfies Dialect
104108
}
109+
110+
export function clickhouseColdDialect() {
111+
return {
112+
createAdapter: clickhouseAdapter,
113+
createDriver: () => new DummyDriver(),
114+
createQueryCompiler: () => new MysqlQueryCompiler(),
115+
createIntrospector: () => {
116+
throw new Error('Not implemented')
117+
},
118+
} satisfies Dialect
119+
}

apps/desktop/src/entities/connection/dialects/index.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,25 @@ import type { Database as PostgresDatabase } from './postgres/schema'
66
import type { connections } from '~/drizzle'
77
import { memoize } from '@conar/shared/utils/helpers'
88
import { Kysely } from 'kysely'
9-
import { clickhouseDialect } from './clickhouse'
10-
import { mssqlDialect } from './mssql'
11-
import { mysqlDialect } from './mysql'
12-
import { postgresDialect } from './postgres'
9+
import { clickhouseColdDialect, clickhouseDialect } from './clickhouse'
10+
import { mssqlColdDialect, mssqlDialect } from './mssql'
11+
import { mysqlColdDialect, mysqlDialect } from './mysql'
12+
import { postgresColdDialect, postgresDialect } from './postgres'
13+
14+
const coldDialects = {
15+
postgres: postgresColdDialect,
16+
mysql: mysqlColdDialect,
17+
clickhouse: clickhouseColdDialect,
18+
mssql: mssqlColdDialect,
19+
} satisfies Record<ConnectionType, () => unknown>
1320

1421
export const dialects = {
1522
postgres: memoize((connection: typeof connections.$inferSelect) => new Kysely<PostgresDatabase>({ dialect: postgresDialect(connection) })),
1623
mysql: memoize((connection: typeof connections.$inferSelect) => new Kysely<MysqlDatabase>({ dialect: mysqlDialect(connection) })),
1724
clickhouse: memoize((connection: typeof connections.$inferSelect) => new Kysely<ClickhouseDatabase>({ dialect: clickhouseDialect(connection) })),
1825
mssql: memoize((connection: typeof connections.$inferSelect) => new Kysely<MssqlDatabase>({ dialect: mssqlDialect(connection) })),
1926
} satisfies Record<ConnectionType, (connection: typeof connections.$inferSelect) => unknown>
27+
28+
export function getColdDialect(dialect: ConnectionType) {
29+
return new Kysely<Record<string, Record<string, unknown>>>({ dialect: coldDialects[dialect]() })
30+
}

apps/desktop/src/entities/connection/dialects/mssql/index.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type {
99
SelectQueryNode,
1010
} from 'kysely'
1111
import type { connections } from '~/drizzle'
12-
import { MssqlQueryCompiler as DefaultMssqlQueryCompiler, MssqlAdapter } from 'kysely'
12+
import { MssqlQueryCompiler as DefaultMssqlQueryCompiler, DummyDriver, MssqlAdapter } from 'kysely'
1313
import { logSql } from '../../sql'
1414

1515
function isSelectQueryNode(node: OperationNode): node is SelectQueryNode {
@@ -98,3 +98,14 @@ export function mssqlDialect(connection: typeof connections.$inferSelect) {
9898
},
9999
} satisfies Dialect
100100
}
101+
102+
export function mssqlColdDialect() {
103+
return {
104+
createDriver: () => new DummyDriver(),
105+
createQueryCompiler: () => new MssqlQueryCompiler(),
106+
createAdapter: () => new MssqlAdapter(),
107+
createIntrospector: () => {
108+
throw new Error('Not implemented')
109+
},
110+
} satisfies Dialect
111+
}

apps/desktop/src/entities/connection/dialects/mysql/index.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { CompiledQuery, Dialect, Driver, QueryResult } from 'kysely'
22
import type { connections } from '~/drizzle'
3-
import { MysqlAdapter, MysqlQueryCompiler } from 'kysely'
3+
import { DummyDriver, MysqlAdapter, MysqlQueryCompiler } from 'kysely'
44
import { logSql } from '../../sql'
55

66
function execute(connection: typeof connections.$inferSelect, compiledQuery: CompiledQuery) {
@@ -57,3 +57,14 @@ export function mysqlDialect(connection: typeof connections.$inferSelect) {
5757
},
5858
} satisfies Dialect
5959
}
60+
61+
export function mysqlColdDialect() {
62+
return {
63+
createDriver: () => new DummyDriver(),
64+
createQueryCompiler: () => new MysqlQueryCompiler(),
65+
createAdapter: () => new MysqlAdapter(),
66+
createIntrospector: () => {
67+
throw new Error('Not implemented')
68+
},
69+
} satisfies Dialect
70+
}

apps/desktop/src/entities/connection/dialects/mysql/schema/information.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export interface InformationSchema {
99
TABLE_CONSTRAINTS: TableConstraints
1010
KEY_COLUMN_USAGE: KeyColumnUsage
1111
STATISTICS: Statistics
12+
REFERENTIAL_CONSTRAINTS: ReferentialConstraints
1213
}
1314

1415
/**
@@ -129,3 +130,21 @@ interface Statistics {
129130
COLUMN_NAME: string
130131
NON_UNIQUE: number
131132
}
133+
134+
/**
135+
* @name REFERENTIAL_CONSTRAINTS
136+
* @type table
137+
*/
138+
interface ReferentialConstraints {
139+
CONSTRAINT_CATALOG: string
140+
CONSTRAINT_SCHEMA: string
141+
CONSTRAINT_NAME: string
142+
UNIQUE_CONSTRAINT_CATALOG: string
143+
UNIQUE_CONSTRAINT_SCHEMA: string
144+
UNIQUE_CONSTRAINT_NAME: string
145+
MATCH_OPTION: string
146+
UPDATE_RULE: string
147+
DELETE_RULE: string
148+
TABLE_NAME: string
149+
REFERENCED_TABLE_NAME: string
150+
}

apps/desktop/src/entities/connection/dialects/postgres/index.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { CompiledQuery, Dialect, Driver, QueryResult } from 'kysely'
22
import type { connections } from '~/drizzle'
3-
import { PostgresAdapter, PostgresQueryCompiler } from 'kysely'
3+
import { DummyDriver, PostgresAdapter, PostgresQueryCompiler } from 'kysely'
44
import { logSql } from '../../sql'
55

66
function execute(connection: typeof connections.$inferSelect, compiledQuery: CompiledQuery) {
@@ -57,3 +57,14 @@ export function postgresDialect(connection: typeof connections.$inferSelect) {
5757
},
5858
} satisfies Dialect
5959
}
60+
61+
export function postgresColdDialect() {
62+
return {
63+
createDriver: () => new DummyDriver(),
64+
createQueryCompiler: () => new PostgresQueryCompiler(),
65+
createAdapter: () => new PostgresAdapter(),
66+
createIntrospector: () => {
67+
throw new Error('Not implemented')
68+
},
69+
} satisfies Dialect
70+
}

0 commit comments

Comments
 (0)