-
-
Notifications
You must be signed in to change notification settings - Fork 108
feat(desktop): adds indexes and constraints page #269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
58 commits
Select commit
Hold shift + click to select a range
2d8bf02
feat: adds indexes and constraints page
Rudra-Sankha-Sinhamahapatra 30e13ba
fix: handling rendering
Rudra-Sankha-Sinhamahapatra c85bcf6
fix: handling rendering
Rudra-Sankha-Sinhamahapatra 6078a7a
Merge branch 'main' of https://github.com/wannabespace/conar into fea…
Rudra-Sankha-Sinhamahapatra ada5552
refactor: using snake_case instead of CamelCase on sql query names
Rudra-Sankha-Sinhamahapatra f950a34
refactor: placing interfaces on appropriate files
Rudra-Sankha-Sinhamahapatra 58519d1
refactor: using types on dialects
Rudra-Sankha-Sinhamahapatra 906ffe5
refactor: using ...data
Rudra-Sankha-Sinhamahapatra 9627f92
feat: added filters & refresh button on pages
Rudra-Sankha-Sinhamahapatra 92c9c01
refactor: codes with required changes
Rudra-Sankha-Sinhamahapatra f4e73e1
Merge branch 'main' of https://github.com/wannabespace/conar into fea…
letstri b8a7755
fix: conflicts
Rudra-Sankha-Sinhamahapatra 930eaad
fix: merge with main
Rudra-Sankha-Sinhamahapatra b33d546
refactor: placing constraints & inside inside a single page with a le…
Rudra-Sankha-Sinhamahapatra 5711563
fix: merge conflicts
Rudra-Sankha-Sinhamahapatra fe92a2c
chore: merge with main
Rudra-Sankha-Sinhamahapatra ce2e142
refactor: remove exports
Rudra-Sankha-Sinhamahapatra eb79119
refactor: required changes
Rudra-Sankha-Sinhamahapatra ee7cb6e
Merge branch 'main' of https://github.com/wannabespace/conar into fea…
Rudra-Sankha-Sinhamahapatra 510e459
Merge branch 'main' of https://github.com/wannabespace/conar into fea…
Rudra-Sankha-Sinhamahapatra 5ecd6dd
Merge branch 'main' of https://github.com/wannabespace/conar into fea…
letstri ab620c0
feat(database): add lastOpenedDefinition to database store type
letstri b524696
refactor: moved enums inside definitions
Rudra-Sankha-Sinhamahapatra b7f31e5
fix: keeping definitions sidebar and main component inside a single b…
Rudra-Sankha-Sinhamahapatra 29fd2eb
fix: primary key showcase on index page
Rudra-Sankha-Sinhamahapatra dbafca3
fix: spacing between item1 on item2 inside constraints page
Rudra-Sankha-Sinhamahapatra 51ee045
refactor: putting filters below the headers
Rudra-Sankha-Sinhamahapatra bde1d2c
fix: gap inside select
Rudra-Sankha-Sinhamahapatra 4a6aee5
Merge branch 'main' of https://github.com/wannabespace/conar into fea…
letstri 9a4b598
Merge branch 'main' of https://github.com/wannabespace/conar into fea…
letstri f0a995e
fix: lint errors
Rudra-Sankha-Sinhamahapatra c3fb3bd
fix: lint errors
Rudra-Sankha-Sinhamahapatra 692216b
Merge branch 'main' of https://github.com/wannabespace/conar into fea…
letstri fa6b84b
Merge branch 'main' of https://github.com/wannabespace/conar into fea…
letstri 6414d9f
Merge branch 'main' of https://github.com/wannabespace/conar into fea…
letstri 837b37e
Merge branch 'main' of https://github.com/wannabespace/conar into fea…
Rudra-Sankha-Sinhamahapatra c656748
Merge branch 'main' of https://github.com/wannabespace/conar into fea…
Rudra-Sankha-Sinhamahapatra 12a8bb6
Merge branch 'main' of https://github.com/wannabespace/conar into fea…
letstri 179626d
Merge branch 'main' of https://github.com/wannabespace/conar into fea…
Rudra-Sankha-Sinhamahapatra 6ec397f
fix: made definitions sidebar as same as tables page
Rudra-Sankha-Sinhamahapatra 96e8c27
feat: adds tabs for recentlyOpenedDefinitions inside definitions page
Rudra-Sankha-Sinhamahapatra 2c71786
Merge branch 'main' of https://github.com/wannabespace/conar into fea…
letstri faa994c
refactor(definitions): streamline definitions page layout
letstri b38d009
Merge branch 'main' of https://github.com/wannabespace/conar into fea…
letstri 3e6699b
Merge branch 'main' of https://github.com/wannabespace/conar into fea…
letstri 7e1d4ca
refactor: simplify
letstri 767bf48
feat: adds skeleton
Rudra-Sankha-Sinhamahapatra 9b34996
Merge branch 'feat/index-page' of https://github.com/wannabespace/con…
Rudra-Sankha-Sinhamahapatra 040e0e7
fix: added skeleton on refetching also
Rudra-Sankha-Sinhamahapatra ef4c49f
refactor: simplify label showing
Rudra-Sankha-Sinhamahapatra b7df028
refactor: add MOTION_BLOCK_PROPS for consistent animation settings
letstri 7ec925a
Merge branch 'feat/index-page' of https://github.com/wannabespace/con…
letstri 586b58b
refactor: definitions
letstri c580251
feat: enhance DefinitionsHeader with refresh functionality and add Se…
letstri c86d9dd
feat: update routing and sidebar for enums, adjust layout spacing in …
letstri 7cb4257
feat: update icons and improve layout for database constraints, enums…
letstri 954ff05
feat: enhance database constraints and indexes pages with highlighted…
letstri 3e0302d
refactor: update connection store type and clean up definitions layout
letstri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
apps/desktop/src/entities/database/dialects/mssql/schema/indexes.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /** | ||
| * @name indexes | ||
| * @type table | ||
| */ | ||
| export interface SysIndexes { | ||
| object_id: number | ||
| index_id: number | ||
| name: string | ||
| is_unique: boolean | ||
| is_primary_key: boolean | ||
| } | ||
|
|
||
| /** | ||
| * @name tables | ||
| * @type table | ||
| */ | ||
| export interface SysTables { | ||
| object_id: number | ||
| schema_id: number | ||
| name: string | ||
| } | ||
|
|
||
| /** | ||
| * @name schemas | ||
| * @type table | ||
| */ | ||
| export interface SysSchemas { | ||
| schema_id: number | ||
| name: string | ||
| } | ||
|
|
||
| /** | ||
| * @name index_columns | ||
| * @type table | ||
| */ | ||
| export interface SysIndexColumns { | ||
| object_id: number | ||
| index_id: number | ||
| column_id: number | ||
| } | ||
|
|
||
| /** | ||
| * @name columns | ||
| * @type table | ||
| */ | ||
| export interface SysColumns { | ||
| object_id: number | ||
| column_id: number | ||
| name: string | ||
| } |
12 changes: 12 additions & 0 deletions
12
apps/desktop/src/entities/database/dialects/mysql/schema/indexes.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| /** | ||
| * @name statistics | ||
| * @type table | ||
| */ | ||
|
|
||
| export interface MysqlStatistics { | ||
| TABLE_SCHEMA: string | ||
| TABLE_NAME: string | ||
| INDEX_NAME: string | ||
| COLUMN_NAME: string | ||
| NON_UNIQUE: number | ||
| } |
13 changes: 2 additions & 11 deletions
13
apps/desktop/src/entities/database/dialects/postgres/schema/catalog.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,9 @@ | ||
| import type { PgNamespace } from './indexes' | ||
|
|
||
| /** | ||
| * @name pg_catalog | ||
| * @type schema | ||
| */ | ||
| export interface PgCatalog { | ||
| pg_namespace: PgNamespace | ||
| } | ||
|
|
||
| /** | ||
| * @name pg_namespace | ||
| * @type table | ||
| */ | ||
| interface PgNamespace { | ||
| oid: number | ||
| nspname: string | ||
| nspowner: number | ||
| nspacl: string | null | ||
| } |
43 changes: 43 additions & 0 deletions
43
apps/desktop/src/entities/database/dialects/postgres/schema/indexes.ts
|
Rudra-Sankha-Sinhamahapatra marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /** | ||
| * @name pg_namespace | ||
| * @type table | ||
| */ | ||
| export interface PgNamespace { | ||
| oid: number | ||
| nspname: string | ||
| nspowner: number | ||
| nspacl: string | null | ||
| } | ||
|
|
||
| /** | ||
| * @name pg_class | ||
| * @type table | ||
| */ | ||
| export interface PgClass { | ||
| oid: number | ||
| relname: string | ||
| relnamespace: number | ||
| relkind: string | ||
| } | ||
|
|
||
| /** | ||
| * @name pg_index | ||
| * @type table | ||
| */ | ||
| export interface PgIndex { | ||
| indrelid: number | ||
| indexrelid: number | ||
| indkey: unknown | ||
| indisunique: boolean | ||
| indisprimary: boolean | ||
| } | ||
|
|
||
| /** | ||
| * @name pg_attribute | ||
| * @type table | ||
| */ | ||
| export interface PgAttribute { | ||
| attrelid: number | ||
| attnum: number | ||
| attname: string | ||
| } |
|
Rudra-Sankha-Sinhamahapatra marked this conversation as resolved.
Outdated
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import type { databases } from '~/drizzle' | ||
| import { queryOptions, useQuery } from '@tanstack/react-query' | ||
| import { indexesQuery } from '../sql/indexes' | ||
|
|
||
| export function databaseIndexesQuery({ database }: { database: typeof databases.$inferSelect }) { | ||
| return queryOptions({ | ||
| queryKey: ['database', database.id, 'indexes'], | ||
| queryFn: () => indexesQuery.run(database), | ||
| }) | ||
| } | ||
|
|
||
| export function useDatabaseIndexes(...params: Parameters<typeof databaseIndexesQuery>) { | ||
| return useQuery(databaseIndexesQuery(...params)) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| import type { Kysely } from 'kysely' | ||
| import type { Columns as ClickHouseColumns } from '../dialects/clickhouse/schema/system' | ||
| import type { SysColumns, SysIndexColumns, SysIndexes, SysSchemas, SysTables } from '../dialects/mssql/schema/indexes' | ||
| import type { MysqlStatistics } from '../dialects/mysql/schema/indexes' | ||
| import type { PgAttribute, PgClass, PgIndex, PgNamespace } from '../dialects/postgres/schema/indexes' | ||
| import { type } from 'arktype' | ||
| import { sql } from 'kysely' | ||
| import { createQuery } from '../query' | ||
|
|
||
| export const indexesType = type({ | ||
| schema: 'string', | ||
| table: 'string', | ||
| name: 'string', | ||
| column: 'string', | ||
| isUnique: 'boolean | 1 | 0', | ||
|
Rudra-Sankha-Sinhamahapatra marked this conversation as resolved.
Outdated
|
||
| isPrimary: 'boolean | 1 | 0', | ||
| }).pipe(data => ({ | ||
|
Rudra-Sankha-Sinhamahapatra marked this conversation as resolved.
Outdated
Rudra-Sankha-Sinhamahapatra marked this conversation as resolved.
Outdated
|
||
| ...data, | ||
| isUnique: !!data.isUnique, | ||
| isPrimary: !!data.isPrimary, | ||
| })) | ||
|
|
||
| export const indexesQuery = createQuery({ | ||
| type: indexesType.array(), | ||
| query: () => ({ | ||
| postgres: (db) => { | ||
| const sysDb = db as unknown as Kysely<{ | ||
|
Rudra-Sankha-Sinhamahapatra marked this conversation as resolved.
Outdated
|
||
| pg_class: PgClass | ||
| pg_index: PgIndex | ||
| pg_attribute: PgAttribute | ||
| pg_namespace: PgNamespace | ||
| }> | ||
|
|
||
| return sysDb | ||
| .selectFrom('pg_class as t') | ||
| .innerJoin('pg_index as ix', 't.oid', 'ix.indrelid') | ||
| .innerJoin('pg_class as i', 'i.oid', 'ix.indexrelid') | ||
| .innerJoin('pg_attribute as a', join => join | ||
| .onRef('a.attrelid', '=', 't.oid') | ||
| .on(sql<boolean>`a.attnum = ANY(ix.indkey)`)) | ||
| .innerJoin('pg_namespace as n', 'n.oid', 't.relnamespace') | ||
| .select([ | ||
| 'n.nspname as schema', | ||
| 't.relname as table', | ||
| 'i.relname as name', | ||
| 'a.attname as column', | ||
| 'ix.indisunique as isUnique', | ||
| 'ix.indisprimary as isPrimary', | ||
| ]) | ||
| .where('n.nspname', 'not in', ['pg_catalog', 'information_schema']) | ||
| .where('t.relkind', '=', 'r') | ||
| .execute() | ||
| }, | ||
|
|
||
| mysql: (db) => { | ||
| const sysDb = db as unknown as Kysely<{ | ||
| 'information_schema.STATISTICS': MysqlStatistics | ||
| }> | ||
|
|
||
| return sysDb | ||
| .selectFrom('information_schema.STATISTICS') | ||
| .select([ | ||
| 'TABLE_SCHEMA as schema', | ||
| 'TABLE_NAME as table', | ||
| 'INDEX_NAME as name', | ||
| 'COLUMN_NAME as column', | ||
| eb => eb('NON_UNIQUE', '=', 0).as('isUnique'), | ||
| eb => eb('INDEX_NAME', '=', 'PRIMARY').as('isPrimary'), | ||
| ]) | ||
| .where('TABLE_SCHEMA', 'not in', ['mysql', 'information_schema', 'performance_schema', 'sys']) | ||
| .execute() | ||
| }, | ||
|
|
||
| mssql: (db) => { | ||
| const sysDb = db as unknown as Kysely<{ | ||
| 'sys.indexes': SysIndexes | ||
| 'sys.tables': SysTables | ||
| 'sys.schemas': SysSchemas | ||
| 'sys.index_columns': SysIndexColumns | ||
| 'sys.columns': SysColumns | ||
| }> | ||
|
|
||
| return sysDb | ||
| .selectFrom('sys.indexes as i') | ||
| .innerJoin('sys.tables as t', 't.object_id', 'i.object_id') | ||
| .innerJoin('sys.schemas as s', 's.schema_id', 't.schema_id') | ||
| .innerJoin('sys.index_columns as ic', join => join | ||
| .onRef('ic.object_id', '=', 'i.object_id') | ||
| .onRef('ic.index_id', '=', 'i.index_id')) | ||
| .innerJoin('sys.columns as c', join => join | ||
| .onRef('c.object_id', '=', 'ic.object_id') | ||
| .onRef('c.column_id', '=', 'ic.column_id')) | ||
| .select([ | ||
| 's.name as schema', | ||
| 't.name as table', | ||
| 'i.name as name', | ||
| 'c.name as column', | ||
| 'i.is_unique as isUnique', | ||
| 'i.is_primary_key as isPrimary', | ||
| ]) | ||
| .execute() | ||
| }, | ||
|
|
||
| clickhouse: async (db) => { | ||
| /* ClickHouse uses ORDER BY as its primary key/sorting key (similar to clustered index). | ||
| It doesn't enforce constraints like traditional RDBMS (no foreign keys, unique constraints, etc.). | ||
| We show ORDER BY columns as primary key indexes since that's how ClickHouse optimizes queries. */ | ||
|
|
||
| const sysDb = db as unknown as Kysely<{ | ||
|
Rudra-Sankha-Sinhamahapatra marked this conversation as resolved.
Outdated
|
||
| 'system.columns': ClickHouseColumns | ||
| }> | ||
|
|
||
| const query = await sysDb | ||
| .selectFrom('system.columns') | ||
| .select([ | ||
| 'database as schema', | ||
| 'table', | ||
| 'name as column', | ||
| ]) | ||
| .where('is_in_primary_key', '=', 1) | ||
| .where('database', 'not in', ['system', 'information_schema']) | ||
| .execute() | ||
|
|
||
| return query.map(row => ({ | ||
| ...row, | ||
| name: 'primary_key', | ||
| isUnique: true, | ||
| isPrimary: true, | ||
| })) | ||
| }, | ||
| }), | ||
| }) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.