@kysera/dialects 0.8.1 → 0.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/types.ts CHANGED
@@ -22,6 +22,45 @@ export interface ConnectionConfig {
22
22
  ssl?: boolean | undefined
23
23
  }
24
24
 
25
+ /**
26
+ * Options for schema-aware database operations.
27
+ *
28
+ * @example
29
+ * // PostgreSQL: Query tables in a specific schema
30
+ * await adapter.tableExists(db, 'users', { schema: 'auth' })
31
+ *
32
+ * @example
33
+ * // Multi-tenant: Query tables in tenant-specific schema
34
+ * await adapter.getTables(db, { schema: `tenant_${tenantId}` })
35
+ */
36
+ export interface SchemaOptions {
37
+ /**
38
+ * Schema name for the operation.
39
+ *
40
+ * - PostgreSQL: Defaults to 'public' if not specified
41
+ * - MySQL: Uses DATABASE() (schema = database in MySQL)
42
+ * - SQLite: Not supported (single schema only)
43
+ * - MSSQL: Defaults to 'dbo' if not specified
44
+ */
45
+ schema?: string
46
+ }
47
+
48
+ /**
49
+ * Configuration options for creating dialect adapters
50
+ */
51
+ export interface DialectAdapterOptions {
52
+ /**
53
+ * Default schema for all operations.
54
+ * Can be overridden per-call via SchemaOptions.
55
+ *
56
+ * - PostgreSQL: Defaults to 'public'
57
+ * - MySQL: Uses current database
58
+ * - SQLite: Not applicable
59
+ * - MSSQL: Defaults to 'dbo'
60
+ */
61
+ defaultSchema?: string
62
+ }
63
+
25
64
  /**
26
65
  * Interface for dialect-specific operations
27
66
  */
@@ -29,6 +68,12 @@ export interface DialectAdapter {
29
68
  /** The dialect this adapter handles */
30
69
  readonly dialect: Dialect
31
70
 
71
+ /**
72
+ * Default schema for this adapter.
73
+ * Used when SchemaOptions.schema is not specified.
74
+ */
75
+ readonly defaultSchema: string
76
+
32
77
  /** Get default port for this dialect */
33
78
  getDefaultPort(): number | null
34
79
 
@@ -50,27 +95,74 @@ export interface DialectAdapter {
50
95
  /** Check if error is a not-null constraint violation */
51
96
  isNotNullError(error: unknown): boolean
52
97
 
53
- /** Check if a table exists in the database */
54
- tableExists(db: Kysely<any>, tableName: string): Promise<boolean>
98
+ /**
99
+ * Check if a table exists in the database
100
+ *
101
+ * @param db - Kysely database instance
102
+ * @param tableName - Name of the table to check
103
+ * @param options - Optional schema configuration
104
+ * @returns true if table exists, false otherwise
105
+ *
106
+ * @example
107
+ * // Check in default schema (public)
108
+ * await adapter.tableExists(db, 'users')
109
+ *
110
+ * @example
111
+ * // Check in specific schema
112
+ * await adapter.tableExists(db, 'users', { schema: 'auth' })
113
+ */
114
+ tableExists(db: Kysely<any>, tableName: string, options?: SchemaOptions): Promise<boolean>
55
115
 
56
- /** Get column names for a table */
57
- getTableColumns(db: Kysely<any>, tableName: string): Promise<string[]>
116
+ /**
117
+ * Get column names for a table
118
+ *
119
+ * @param db - Kysely database instance
120
+ * @param tableName - Name of the table
121
+ * @param options - Optional schema configuration
122
+ * @returns Array of column names
123
+ *
124
+ * @example
125
+ * const columns = await adapter.getTableColumns(db, 'users', { schema: 'auth' })
126
+ * // ['id', 'email', 'password_hash', 'created_at']
127
+ */
128
+ getTableColumns(db: Kysely<any>, tableName: string, options?: SchemaOptions): Promise<string[]>
58
129
 
59
- /** Get all tables in the database */
60
- getTables(db: Kysely<any>): Promise<string[]>
130
+ /**
131
+ * Get all tables in the database/schema
132
+ *
133
+ * @param db - Kysely database instance
134
+ * @param options - Optional schema configuration
135
+ * @returns Array of table names
136
+ *
137
+ * @example
138
+ * // Get tables in auth schema
139
+ * const tables = await adapter.getTables(db, { schema: 'auth' })
140
+ * // ['users', 'sessions', 'tokens']
141
+ */
142
+ getTables(db: Kysely<any>, options?: SchemaOptions): Promise<string[]>
61
143
 
62
144
  /** Get database size in bytes */
63
145
  getDatabaseSize(db: Kysely<any>, databaseName?: string): Promise<number>
64
146
 
65
147
  /**
66
148
  * Truncate a single table
149
+ *
150
+ * @param db - Kysely database instance
151
+ * @param tableName - Name of the table to truncate
152
+ * @param options - Optional schema configuration
67
153
  * @returns true if table was truncated, false if table does not exist
68
154
  * @throws Error for other database errors
69
155
  */
70
- truncateTable(db: Kysely<any>, tableName: string): Promise<boolean>
156
+ truncateTable(db: Kysely<any>, tableName: string, options?: SchemaOptions): Promise<boolean>
71
157
 
72
- /** Truncate all tables (for testing) */
73
- truncateAllTables(db: Kysely<any>, exclude?: string[]): Promise<void>
158
+ /**
159
+ * Truncate all tables in the database/schema (for testing)
160
+ *
161
+ * @param db - Kysely database instance
162
+ * @param exclude - Array of table names to exclude
163
+ * @param options - Optional schema configuration
164
+ */
165
+ truncateAllTables(db: Kysely<any>, exclude?: string[], options?: SchemaOptions): Promise<void>
74
166
  }
75
167
 
76
168
  /**
@@ -79,4 +171,6 @@ export interface DialectAdapter {
79
171
  export interface DatabaseErrorLike {
80
172
  message?: string
81
173
  code?: string
174
+ /** Error number (used by MSSQL for error codes like 2627, 547, 515) */
175
+ number?: number
82
176
  }