|
| 1 | +// MixDB shared types for SDK and app consumers |
| 2 | + |
| 3 | +export interface MixQuery { |
| 4 | + toQueryParams(): Record<string, any>; |
| 5 | +} |
| 6 | + |
| 7 | +export interface TableInfo { |
| 8 | + id: string; |
| 9 | + name: string; |
| 10 | + displayName: string; |
| 11 | + description?: string; |
| 12 | + recordCount: number; |
| 13 | + createdDate: string; |
| 14 | + lastModified: string; |
| 15 | + schema: TableSchema; |
| 16 | + isSystemTable: boolean; |
| 17 | +} |
| 18 | + |
| 19 | +export interface TableSchema { |
| 20 | + columns: ColumnDefinition[]; |
| 21 | + primaryKey: string; |
| 22 | + indexes: IndexDefinition[]; |
| 23 | + relationships: RelationshipDefinition[]; |
| 24 | +} |
| 25 | + |
| 26 | +export interface ColumnDefinition { |
| 27 | + name: string; |
| 28 | + type: string; |
| 29 | + isRequired: boolean; |
| 30 | + isUnique: boolean; |
| 31 | + defaultValue?: any; |
| 32 | + maxLength?: number; |
| 33 | + description?: string; |
| 34 | +} |
| 35 | + |
| 36 | +export interface IndexDefinition { |
| 37 | + name: string; |
| 38 | + columns: string[]; |
| 39 | + isUnique: boolean; |
| 40 | + type: 'btree' | 'hash' | 'gin' | 'gist'; |
| 41 | +} |
| 42 | + |
| 43 | +export interface RelationshipDefinition { |
| 44 | + name: string; |
| 45 | + type: 'one-to-one' | 'one-to-many' | 'many-to-many' | 'many-to-one'; |
| 46 | + targetTable: string; |
| 47 | + targetColumn: string; |
| 48 | + sourceColumn: string; |
| 49 | + onDelete: 'cascade' | 'restrict' | 'set-null'; |
| 50 | + onUpdate: 'cascade' | 'restrict' | 'set-null'; |
| 51 | +} |
| 52 | + |
| 53 | +export interface RecordData { |
| 54 | + [key: string]: any; |
| 55 | +} |
| 56 | + |
| 57 | +export interface QueryResult<T = RecordData> { |
| 58 | + data: T[]; |
| 59 | + count: number; |
| 60 | + page: number; |
| 61 | + pageSize: number; |
| 62 | + totalPages: number; |
| 63 | + hasNext: boolean; |
| 64 | + hasPrevious: boolean; |
| 65 | +} |
| 66 | + |
| 67 | +export interface DatabaseStats { |
| 68 | + totalTables: number; |
| 69 | + totalRecords: number; |
| 70 | + databaseSize: string; |
| 71 | + lastBackup?: string; |
| 72 | + isConnected: boolean; |
| 73 | +} |
| 74 | + |
| 75 | +export interface CreateTableRequest { |
| 76 | + name: string; |
| 77 | + displayName: string; |
| 78 | + description?: string; |
| 79 | + columns: Omit<ColumnDefinition, 'name'>[]; |
| 80 | + primaryKey?: string; |
| 81 | +} |
| 82 | + |
| 83 | +export interface UpdateTableRequest { |
| 84 | + displayName?: string; |
| 85 | + description?: string; |
| 86 | + addColumns?: ColumnDefinition[]; |
| 87 | + dropColumns?: string[]; |
| 88 | + modifyColumns?: ColumnDefinition[]; |
| 89 | +} |
| 90 | + |
| 91 | +export interface QueryOptions { |
| 92 | + page?: number; |
| 93 | + pageSize?: number; |
| 94 | + orderBy?: string; |
| 95 | + orderDirection?: 'asc' | 'desc'; |
| 96 | + filters?: FilterCondition[]; |
| 97 | + search?: string; |
| 98 | + searchColumns?: string[]; |
| 99 | +} |
| 100 | + |
| 101 | +export interface FilterCondition { |
| 102 | + column: string; |
| 103 | + operator: 'eq' | 'neq' | 'gt' | 'gte' | 'lt' | 'lte' | 'like' | 'in' | 'notin' | 'isnull' | 'isnotnull'; |
| 104 | + value: any; |
| 105 | +} |
| 106 | + |
| 107 | +export interface DatabaseOperationResult { |
| 108 | + success: boolean; |
| 109 | + data?: any; |
| 110 | + error?: string; |
| 111 | + message?: string; |
| 112 | +} |
0 commit comments