-
-
Notifications
You must be signed in to change notification settings - Fork 108
feat(connections): fetch server connections #240
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 1 commit
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
2da5693
feat: fetch server databases
Rudra-Sankha-Sinhamahapatra 7becb57
refactor: using useQuery & map
Rudra-Sankha-Sinhamahapatra c43c0cc
fix: database-list height issue
Rudra-Sankha-Sinhamahapatra 56bea03
fix: merge with main
Rudra-Sankha-Sinhamahapatra e48c03a
Merge branch 'main' of https://github.com/wannabespace/conar into fea…
letstri b573321
Merge branch 'main' of https://github.com/wannabespace/conar into fea…
Rudra-Sankha-Sinhamahapatra a6f058b
fix: skip default databases
Rudra-Sankha-Sinhamahapatra fee20de
fix: show expand button only if database more than 0
Rudra-Sankha-Sinhamahapatra 3031370
fix: merge conflicts
Rudra-Sankha-Sinhamahapatra 4588070
fix: merge conflicts
Rudra-Sankha-Sinhamahapatra cbbc680
Merge branch 'main' of https://github.com/wannabespace/conar into fea…
Rudra-Sankha-Sinhamahapatra e11a6f5
Merge branch 'main' of https://github.com/wannabespace/conar into fea…
Rudra-Sankha-Sinhamahapatra 11dbe23
Merge branch 'main' of https://github.com/wannabespace/conar into fea…
Rudra-Sankha-Sinhamahapatra 34dc24f
refactor: merge with main
Rudra-Sankha-Sinhamahapatra 5f0bc53
fix: merge conflicts
Rudra-Sankha-Sinhamahapatra 5a3ebe0
fix: connection string false copy on toggle
Rudra-Sankha-Sinhamahapatra 1e5fed0
refactor: made separate components for database-lists
Rudra-Sankha-Sinhamahapatra d4c2e37
fix: merge conflicts
Rudra-Sankha-Sinhamahapatra 1808216
refactor: fixes merge conflict and refactor comp names
Rudra-Sankha-Sinhamahapatra ead5d2d
refactor: adds error handling and removed empty onKeyDown
Rudra-Sankha-Sinhamahapatra 2862824
Merge branch 'main' of https://github.com/wannabespace/conar into fea…
Rudra-Sankha-Sinhamahapatra 91bbee5
refactor: remove retry:5
Rudra-Sankha-Sinhamahapatra 38de4de
fix: merge conflicts
Rudra-Sankha-Sinhamahapatra d60befc
Merge branch 'main' of https://github.com/wannabespace/conar into fea…
Rudra-Sankha-Sinhamahapatra 01d23a3
refactor: remove clone connection
letstri f0cc3dd
Merge branch 'main' of https://github.com/wannabespace/conar into fea…
Rudra-Sankha-Sinhamahapatra 80d4811
Merge branch 'feat/server-databases' of https://github.com/wannabespa…
Rudra-Sankha-Sinhamahapatra 02bddef
Merge branch 'main' of https://github.com/wannabespace/conar into fea…
Rudra-Sankha-Sinhamahapatra a64d450
Merge branch 'main' of https://github.com/wannabespace/conar into fea…
Rudra-Sankha-Sinhamahapatra 6b9f395
feat(connections): open server connections
Rudra-Sankha-Sinhamahapatra c23340d
fix: merge conflicts
Rudra-Sankha-Sinhamahapatra fb76135
Merge branch 'main' of https://github.com/wannabespace/conar into fea…
Rudra-Sankha-Sinhamahapatra 54d662c
Merge branch 'main' of https://github.com/wannabespace/conar into fea…
Rudra-Sankha-Sinhamahapatra c9817b8
Merge branch 'main' of https://github.com/wannabespace/conar into fea…
letstri 64fb19b
Merge branch 'main' of https://github.com/wannabespace/conar into fea…
Rudra-Sankha-Sinhamahapatra a0c625a
Merge branch 'main' of https://github.com/wannabespace/conar into fea…
Rudra-Sankha-Sinhamahapatra 11d7b07
feat: implement resources
letstri a153d1f
Merge branch 'main' of https://github.com/wannabespace/conar into fea…
letstri 74ed036
refactor: rename SQL references to query
letstri 1cd2773
fix: clickhouse connections
letstri 2fd673c
Merge branch 'main' of https://github.com/wannabespace/conar into fea…
letstri 94d52e2
feat: new dashboard page
letstri 30d6bc2
refactor: improve list
letstri 0677cf8
Merge branch 'main' of https://github.com/wannabespace/conar into fea…
letstri 82483fe
chore: update tanstack store
letstri b51e821
fix: lint error
Rudra-Sankha-Sinhamahapatra c5d4811
fix: rendering logic
Rudra-Sankha-Sinhamahapatra 1deb49c
feat: add shadows on scroll
letstri 5d66842
Merge branch 'feat/server-databases' of https://github.com/wannabespa…
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
3 changes: 3 additions & 0 deletions
3
apps/desktop/src/entities/database/dialects/clickhouse/schema/index.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,4 +1,7 @@ | ||
| import type { WithSchema } from '../../../utils/types' | ||
| import type { InformationSchema } from './information' | ||
|
|
||
| import type { System } from './system' | ||
|
|
||
| export type Database = WithSchema<InformationSchema, 'information_schema'> | ||
| & WithSchema<System, 'system'> |
20 changes: 20 additions & 0 deletions
20
apps/desktop/src/entities/database/dialects/clickhouse/schema/system.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,20 @@ | ||
| /** | ||
| * @name system | ||
| * @type schema | ||
| */ | ||
| export interface System { | ||
| databases: Databases | ||
| } | ||
|
|
||
| /** | ||
| * @name databases | ||
| * @type table | ||
| */ | ||
| interface Databases { | ||
| name: string | ||
| engine: string | ||
| data_path: string | ||
| metadata_path: string | ||
| uuid: string | ||
| comment: string | ||
| } |
3 changes: 3 additions & 0 deletions
3
apps/desktop/src/entities/database/dialects/mssql/schema/index.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,4 +1,7 @@ | ||
| import type { WithSchema } from '../../../utils/types' | ||
| import type { InformationSchema } from './information' | ||
|
|
||
| import type { Sys } from './sys' | ||
|
|
||
| export type Database = WithSchema<InformationSchema, 'information_schema'> | ||
| & WithSchema<Sys, 'sys'> |
88 changes: 88 additions & 0 deletions
88
apps/desktop/src/entities/database/dialects/mssql/schema/sys.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,88 @@ | ||
| /** | ||
| * @name sys | ||
| * @type schema | ||
| */ | ||
| export interface Sys { | ||
| databases: Databases | ||
| } | ||
|
|
||
| /** | ||
| * @name databases | ||
| * @type table | ||
| */ | ||
| interface Databases { | ||
| name: string | ||
| database_id: number | ||
| source_database_id: number | null | ||
| owner_sid: string | ||
| create_date: Date | ||
| compatibility_level: number | ||
| collation_name: string | null | ||
| user_access: number | ||
| user_access_desc: string | null | ||
| is_read_only: boolean | ||
| is_auto_shrink_on: boolean | ||
| state: number | ||
| state_desc: string | null | ||
| is_in_standby: boolean | ||
| is_cleanly_shutdown: boolean | ||
| is_supplemental_logging_enabled: boolean | ||
| snapshot_isolation_state: number | ||
| snapshot_isolation_state_desc: string | null | ||
| recovery_model: number | ||
| recovery_model_desc: string | null | ||
| page_verify_option: number | ||
| page_verify_option_desc: string | null | ||
| is_auto_create_stats_on: boolean | ||
| is_auto_update_stats_on: boolean | ||
| is_auto_update_stats_async_on: boolean | ||
| is_ansi_null_default_on: boolean | ||
| is_ansi_nulls_on: boolean | ||
| is_ansi_padding_on: boolean | ||
| is_ansi_warnings_on: boolean | ||
| is_arithabort_on: boolean | ||
| is_concat_null_yields_null_on: boolean | ||
| is_numeric_roundabort_on: boolean | ||
| is_quoted_identifier_on: boolean | ||
| is_recursive_triggers_on: boolean | ||
| is_cursor_close_on_commit_on: boolean | ||
| is_local_cursor_default: boolean | ||
| is_fulltext_enabled: boolean | ||
| is_trustworthy_on: boolean | ||
| is_db_chaining_on: boolean | ||
| is_parameterization_forced: boolean | ||
| is_master_key_encrypted_by_server: boolean | ||
| is_query_store_on: boolean | ||
| is_published: boolean | ||
| is_subscribed: boolean | ||
| is_merge_published: boolean | ||
| is_distributor: boolean | ||
| is_sync_with_backup: boolean | ||
| service_broker_guid: string | ||
| is_broker_enabled: boolean | ||
| log_reuse_wait: number | ||
| log_reuse_wait_desc: string | null | ||
| is_date_correlation_on: boolean | ||
| is_cdc_enabled: boolean | ||
| is_encrypted: boolean | ||
| is_honor_broker_priority_on: boolean | ||
| replica_id: string | null | ||
| group_database_id: string | null | ||
| resource_pool_id: number | null | ||
| default_language_lcid: number | null | ||
| default_language_name: string | null | ||
| default_fulltext_language_lcid: number | null | ||
| default_fulltext_language_name: string | null | ||
| is_nested_triggers_on: boolean | null | ||
| is_transform_noise_words_on: boolean | null | ||
| two_digit_year_cutoff: number | null | ||
| containment: number | null | ||
| containment_desc: string | null | ||
| target_recovery_time_in_seconds: number | null | ||
| delayed_durability: number | null | ||
| delayed_durability_desc: string | null | ||
| is_memory_optimized_elevate_to_snapshot_on: boolean | null | ||
| is_federation_member: boolean | null | ||
| is_remote_data_archive_enabled: boolean | null | ||
| is_mixed_page_allocation_on: boolean | null | ||
| } |
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
66 changes: 66 additions & 0 deletions
66
apps/desktop/src/entities/database/hooks/use-server-databases.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,66 @@ | ||
| import type { databases } from '~/drizzle' | ||
| import { DatabaseType } from '@conar/shared/enums/database-type' | ||
| import { SafeURL } from '@conar/shared/utils/safe-url' | ||
| import { useState } from 'react' | ||
| import { listDatabasesQuery } from '../sql/list-databases' | ||
|
|
||
| export function useServerDatabases(database: typeof databases.$inferSelect) { | ||
| const [isExpanded, setIsExpanded] = useState(false) | ||
| const [databasesList, setDatabasesList] = useState<string[]>([]) | ||
| const [isLoading, setIsLoading] = useState(false) | ||
|
|
||
| const toggleExpand = async () => { | ||
| if (isExpanded) { | ||
| setIsExpanded(false) | ||
| return | ||
| } | ||
|
|
||
| setIsExpanded(true) | ||
|
|
||
| if (databasesList.length === 0) { | ||
| setIsLoading(true) | ||
| const url = new SafeURL(database.connectionString) | ||
|
|
||
| switch (database.type) { | ||
| case DatabaseType.Postgres: | ||
| url.pathname = 'postgres' | ||
| break | ||
| case DatabaseType.MySQL: | ||
| url.pathname = 'mysql' | ||
| break | ||
| case DatabaseType.MSSQL: | ||
| url.pathname = 'master' | ||
| break | ||
| case DatabaseType.ClickHouse: | ||
| url.pathname = 'default' | ||
| break | ||
| } | ||
|
|
||
| const systemDatabase = { | ||
| ...database, | ||
| connectionString: url.toString(), | ||
| } | ||
|
|
||
| try { | ||
| const dbNames = await listDatabasesQuery.run(systemDatabase) | ||
|
Rudra-Sankha-Sinhamahapatra marked this conversation as resolved.
Outdated
|
||
| const currentDbName = new SafeURL(database.connectionString).pathname.replace(/^\//, '') | ||
| const otherDbs = dbNames.filter(name => name !== currentDbName) | ||
| setDatabasesList(otherDbs) | ||
| } | ||
| catch (err) { | ||
| console.error('Failed to list databases', err) | ||
| } | ||
| finally { | ||
| setIsLoading(false) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return { | ||
| isExpanded, | ||
| isLoading, | ||
| databasesList, | ||
| toggleExpand, | ||
| setIsExpanded, | ||
| } | ||
| } | ||
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,38 @@ | ||
| import { type } from 'arktype' | ||
| import { createQuery } from '../query' | ||
|
|
||
| export const listDatabasesType = type('string[]') | ||
|
|
||
| export const listDatabasesQuery = createQuery({ | ||
| type: listDatabasesType, | ||
| query: () => ({ | ||
| postgres: db => db | ||
| .selectFrom('pg_catalog.pg_database') | ||
| .select('datname') | ||
| .where('datistemplate', '=', false) | ||
| .orderBy('datname') | ||
| .execute() | ||
| .then(rows => rows.map(r => r.datname)), | ||
|
|
||
| mysql: db => db | ||
| .selectFrom('information_schema.SCHEMATA') | ||
| .select('SCHEMA_NAME') | ||
| .orderBy('SCHEMA_NAME') | ||
| .execute() | ||
| .then(rows => rows.map(r => r.SCHEMA_NAME)), | ||
|
|
||
| mssql: db => db | ||
| .selectFrom('sys.databases') | ||
| .select('name') | ||
| .orderBy('name') | ||
| .execute() | ||
| .then(rows => rows.map(r => r.name)), | ||
|
|
||
| clickhouse: db => db | ||
| .selectFrom('system.databases') | ||
| .select('name') | ||
| .orderBy('name') | ||
| .execute() | ||
| .then(rows => rows.map(r => r.name)), | ||
| }), | ||
| }) |
20 changes: 20 additions & 0 deletions
20
apps/desktop/src/entities/database/utils/clone-connection.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,20 @@ | ||
| import type { databases } from '~/drizzle' | ||
| import { SafeURL } from '@conar/shared/utils/safe-url' | ||
| import { v7 } from 'uuid' | ||
|
|
||
| export function cloneConnectionForDatabase( | ||
|
Rudra-Sankha-Sinhamahapatra marked this conversation as resolved.
Outdated
|
||
| originalDatabase: typeof databases.$inferSelect, | ||
| newDatabaseName: string, | ||
| ) { | ||
| const url = new SafeURL(originalDatabase.connectionString) | ||
| url.pathname = newDatabaseName | ||
|
|
||
| return { | ||
| ...originalDatabase, | ||
| id: v7(), | ||
| name: newDatabaseName, | ||
| connectionString: url.toString(), | ||
| createdAt: new Date(), | ||
| updatedAt: new Date(), | ||
| } satisfies typeof databases.$inferSelect | ||
| } | ||
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.