-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,12 +1,51 @@ | ||
import { QueryType } from '../query-params' | ||
import { Query } from '../query' | ||
import { Schema, TableColumn, TableCondition, TableIndex, TableRecord } from 'src/models/database' | ||
|
||
export type OperationResponse = { | ||
success: boolean | ||
data: any | ||
error: Error | null | ||
} | ||
|
||
export interface Connection { | ||
queryType: QueryType | ||
|
||
// Handles logic for securely connecting and properly disposing of the connection. | ||
connect: () => Promise<any> | ||
disconnect: () => Promise<any> | ||
|
||
// Raw query execution method that can be used to execute any query. | ||
query: ( | ||
query: Query | ||
) => Promise<{ data: any; error: Error | null; query: string }> | ||
|
||
// Basic CRUD methods that allow for easy interaction with the connection. | ||
insert?: (record: TableRecord, table: string, schema?: string) => Promise<OperationResponse> | ||
read?: (conditions: TableCondition[], table: string, schema?: string) => Promise<OperationResponse> | ||
update?: (record: TableRecord, conditions: TableCondition[], table: string, schema?: string) => Promise<OperationResponse> | ||
delete?: (conditions: TableCondition[], table: string, schema?: string) => Promise<OperationResponse> | ||
|
||
// Table operations | ||
createTable?: (name: string, schema?: string) => Promise<OperationResponse> | ||
dropTable?: (name: string, schema?: string) => Promise<OperationResponse> | ||
renameTable?: (name: string, original: string, schema?: string) => Promise<OperationResponse> | ||
|
||
// Column operations | ||
addColumn?: (name: string, table: string, schema?: string) => Promise<OperationResponse> | ||
dropColumn?: (name: string, table: string, schema?: string) => Promise<OperationResponse> | ||
renameColumn?: (name: string, original: string, table: string, schema?: string) => Promise<OperationResponse> | ||
updateColumn?: (name: string, column: TableColumn, table: string, schema?: string) => Promise<OperationResponse> | ||
|
||
// Index operations | ||
createIndex?: (index: TableIndex, table: string, schema?: string) => Promise<OperationResponse> | ||
dropIndex?: (name: string, table: string, schema?: string) => Promise<OperationResponse> | ||
renameIndex?: (name: string, original: string, table: string, schema?: string) => Promise<OperationResponse> | ||
|
||
// Schema operations | ||
createSchema?: (name: string) => Promise<OperationResponse> | ||
dropSchema?: (name: string) => Promise<OperationResponse> | ||
|
||
// Additional operations | ||
fetchDatabaseSchema?: () => Promise<Schema[]> | ||
} |
This file contains 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,39 @@ | ||
export type Schema = { | ||
name: string | ||
tables: Table[] | ||
} | ||
|
||
export type Table = { | ||
name: string | ||
schema: string | ||
columns: TableColumn[] | ||
indexes: { | ||
name: string | ||
type: 'unique' | 'primary' | 'index' | ||
columns: string[] | ||
}[] | ||
} | ||
|
||
export type TableColumn = { | ||
name: string | ||
type: string | ||
nullable: boolean | ||
default: any | ||
primary: boolean | ||
unique: boolean | ||
expression: string | ||
references: TableIndex[] | ||
} | ||
|
||
export type TableRecord = Record<string, any> | ||
export type TableCondition = { | ||
column: string | ||
value: any | ||
condition: 'eq' | 'neq' | 'gt' | 'lt' | 'gte' | 'lte' | 'like' | 'in' | 'nin' | ||
} | ||
|
||
export type TableIndex = { | ||
name: string | ||
type: 'unique' | 'primary' | 'index' | ||
columns: string[] | ||
} |