Skip to content

Commit 74347aa

Browse files
feat(desktop): adds indexes and constraints page (#269)
Co-authored-by: Valerii Strilets <valerii.strilets@gmail.com>
1 parent b8ce386 commit 74347aa

33 files changed

Lines changed: 1312 additions & 444 deletions

File tree

apps/api/drizzle/schema/subscriptions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
import { baseTable } from '../base-table'
1212
import { users } from './auth'
1313

14-
export const subscriptionPeriod = pgEnum('subscription_period', ['monthly', 'yearly'] as const)
14+
export const subscriptionPeriod = pgEnum('subscription_period', ['monthly', 'yearly'])
1515

1616
export const subscriptions = pgTable('subscriptions', {
1717
...baseTable,

apps/desktop/src/components/global-banner.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ export function GlobalBanner() {
5858
`}
5959
>
6060
{typeConfig.info.icon}
61-
<span className="flex-1 leading-none">You are offline. Please check your internet connection.</span>
61+
<span className="flex-1 leading-none">
62+
You are currently offline. Some features may be unavailable until your internet connection is restored.
63+
</span>
6264
</div>
6365
</motion.div>
6466
)}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import type { LinkProps } from '@tanstack/react-router'
2+
import type { ComponentProps } from 'react'
3+
import { cn } from '@conar/ui/lib/utils'
4+
import { Link } from '@tanstack/react-router'
5+
6+
export function SidebarLink({
7+
className,
8+
...props
9+
}: LinkProps & Omit<ComponentProps<'a'>, 'children'>) {
10+
return (
11+
<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)}
17+
{...props}
18+
/>
19+
)
20+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import type { WithSchema } from '../../../utils/types'
22
import type { InformationSchema } from './information'
3+
import type { Sys } from './sys'
34

45
export type Database = WithSchema<InformationSchema, 'information_schema'>
6+
& WithSchema<Sys, 'sys'>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* @name sys
3+
* @type schema
4+
*/
5+
export interface Sys {
6+
indexes: Indexes
7+
tables: Tables
8+
schemas: Schemas
9+
index_columns: IndexColumns
10+
columns: Columns
11+
}
12+
13+
/**
14+
* @name indexes
15+
* @type table
16+
*/
17+
interface Indexes {
18+
object_id: number
19+
index_id: number
20+
name: string
21+
is_unique: boolean
22+
is_primary_key: boolean
23+
}
24+
25+
/**
26+
* @name tables
27+
* @type table
28+
*/
29+
interface Tables {
30+
object_id: number
31+
schema_id: number
32+
name: string
33+
}
34+
35+
/**
36+
* @name schemas
37+
* @type table
38+
*/
39+
interface Schemas {
40+
schema_id: number
41+
name: string
42+
}
43+
44+
/**
45+
* @name index_columns
46+
* @type table
47+
*/
48+
interface IndexColumns {
49+
object_id: number
50+
index_id: number
51+
column_id: number
52+
}
53+
54+
/**
55+
* @name columns
56+
* @type table
57+
*/
58+
interface Columns {
59+
object_id: number
60+
column_id: number
61+
name: string
62+
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export interface InformationSchema {
88
VIEWS: Views
99
TABLE_CONSTRAINTS: TableConstraints
1010
KEY_COLUMN_USAGE: KeyColumnUsage
11+
STATISTICS: Statistics
1112
}
1213

1314
/**
@@ -116,3 +117,15 @@ interface KeyColumnUsage {
116117
REFERENCED_TABLE_NAME: string | null
117118
REFERENCED_COLUMN_NAME: string | null
118119
}
120+
121+
/**
122+
* @name STATISTICS
123+
* @type table
124+
*/
125+
interface Statistics {
126+
TABLE_SCHEMA: string
127+
TABLE_NAME: string
128+
INDEX_NAME: string
129+
COLUMN_NAME: string
130+
NON_UNIQUE: number
131+
}

apps/desktop/src/entities/connection/dialects/postgres/schema/catalog.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
*/
55
export interface PgCatalog {
66
pg_namespace: PgNamespace
7+
pg_class: PgClass
8+
pg_index: PgIndex
9+
pg_attribute: PgAttribute
710
}
811

912
/**
@@ -16,3 +19,36 @@ interface PgNamespace {
1619
nspowner: number
1720
nspacl: string | null
1821
}
22+
23+
/**
24+
* @name pg_class
25+
* @type table
26+
*/
27+
interface PgClass {
28+
oid: number
29+
relname: string
30+
relnamespace: number
31+
relkind: string
32+
}
33+
34+
/**
35+
* @name pg_index
36+
* @type table
37+
*/
38+
interface PgIndex {
39+
indrelid: number
40+
indexrelid: number
41+
indkey: unknown
42+
indisunique: boolean
43+
indisprimary: boolean
44+
}
45+
46+
/**
47+
* @name pg_attribute
48+
* @type table
49+
*/
50+
interface PgAttribute {
51+
attrelid: number
52+
attnum: number
53+
attname: string
54+
}

apps/desktop/src/entities/connection/hooks/use-connection-link-params.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ export function useConnectionLinkParams(id: string) {
99

1010
return useMemo((): LinkProps => {
1111
if (lastOpenedPage) {
12-
if (lastOpenedPage === '/_protected/database/$id/enums/') {
12+
if (lastOpenedPage === '/_protected/database/$id/definitions/enums/') {
1313
return {
14-
to: '/database/$id/enums',
14+
to: '/database/$id/definitions/enums',
1515
params: { id },
1616
}
1717
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export * from './columns'
22
export * from './constraints'
33
export * from './enums'
4+
export * from './indexes'
45
export * from './rows'
56
export * from './tables-and-schemas'
67
export * from './total'
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type { connections } from '~/drizzle'
2+
import { queryOptions, useQuery } from '@tanstack/react-query'
3+
import { indexesQuery } from '../sql/index'
4+
5+
export function connectionIndexesQuery({ connection }: { connection: typeof connections.$inferSelect }) {
6+
return queryOptions({
7+
queryKey: ['connection', connection.id, 'indexes'],
8+
queryFn: () => indexesQuery(connection),
9+
})
10+
}
11+
12+
export function useConnectionIndexes(...params: Parameters<typeof connectionIndexesQuery>) {
13+
return useQuery(connectionIndexesQuery(...params))
14+
}

0 commit comments

Comments
 (0)