@happyvertical/sql 0.74.8
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/AGENT.md +33 -0
- package/LICENSE +7 -0
- package/README.md +287 -0
- package/dist/backup/index.d.ts +119 -0
- package/dist/backup/index.d.ts.map +1 -0
- package/dist/backup/index.js +212 -0
- package/dist/backup/index.js.map +1 -0
- package/dist/backup/manifest.d.ts +51 -0
- package/dist/backup/manifest.d.ts.map +1 -0
- package/dist/chunks/duckdb-Djx8WKZE.js +924 -0
- package/dist/chunks/duckdb-Djx8WKZE.js.map +1 -0
- package/dist/chunks/index-DL-5nB7l.js +3468 -0
- package/dist/chunks/index-DL-5nB7l.js.map +1 -0
- package/dist/chunks/postgres-cli-Cr6bBZ3q.js +209 -0
- package/dist/chunks/postgres-cli-Cr6bBZ3q.js.map +1 -0
- package/dist/chunks/sqlite-DkCGjXmu.js +937 -0
- package/dist/chunks/sqlite-DkCGjXmu.js.map +1 -0
- package/dist/chunks/sqlite-native-B6q-0nLs.js +1129 -0
- package/dist/chunks/sqlite-native-B6q-0nLs.js.map +1 -0
- package/dist/cli/claude-context.d.ts +3 -0
- package/dist/cli/claude-context.d.ts.map +1 -0
- package/dist/cli/claude-context.js +21 -0
- package/dist/cli/claude-context.js.map +1 -0
- package/dist/doctor.d.ts +69 -0
- package/dist/doctor.d.ts.map +1 -0
- package/dist/duckdb.d.ts +9 -0
- package/dist/duckdb.d.ts.map +1 -0
- package/dist/index.d.ts +109 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -0
- package/dist/json.d.ts +30 -0
- package/dist/json.d.ts.map +1 -0
- package/dist/postgres-cli.d.ts +135 -0
- package/dist/postgres-cli.d.ts.map +1 -0
- package/dist/postgres.d.ts +77 -0
- package/dist/postgres.d.ts.map +1 -0
- package/dist/schema-manager.d.ts +86 -0
- package/dist/schema-manager.d.ts.map +1 -0
- package/dist/shared/alter-utils.d.ts +83 -0
- package/dist/shared/alter-utils.d.ts.map +1 -0
- package/dist/shared/duckdb-schema-utils.d.ts +86 -0
- package/dist/shared/duckdb-schema-utils.d.ts.map +1 -0
- package/dist/shared/types.d.ts +1016 -0
- package/dist/shared/types.d.ts.map +1 -0
- package/dist/shared/utils.d.ts +104 -0
- package/dist/shared/utils.d.ts.map +1 -0
- package/dist/sqlite-native.d.ts +4 -0
- package/dist/sqlite-native.d.ts.map +1 -0
- package/dist/sqlite.d.ts +54 -0
- package/dist/sqlite.d.ts.map +1 -0
- package/metadata.json +38 -0
- package/package.json +84 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { DatabaseInterface } from './shared/types';
|
|
2
|
+
/**
|
|
3
|
+
* Configuration options for PostgreSQL database connections
|
|
4
|
+
*/
|
|
5
|
+
export interface PostgresOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Connection URL for PostgreSQL
|
|
8
|
+
*/
|
|
9
|
+
url?: string;
|
|
10
|
+
/**
|
|
11
|
+
* Database name
|
|
12
|
+
*/
|
|
13
|
+
database?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Database server hostname
|
|
16
|
+
*/
|
|
17
|
+
host?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Username for authentication
|
|
20
|
+
*/
|
|
21
|
+
user?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Password for authentication
|
|
24
|
+
*/
|
|
25
|
+
password?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Port number for the PostgreSQL server
|
|
28
|
+
*/
|
|
29
|
+
port?: number;
|
|
30
|
+
/**
|
|
31
|
+
* Cache key for connection pooling.
|
|
32
|
+
* If provided, the same dbid returns the same cached connection.
|
|
33
|
+
* When omitted, a key is derived from the connection URL.
|
|
34
|
+
*/
|
|
35
|
+
dbid?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Maximum number of connections in the pool.
|
|
38
|
+
* Defaults to 20. The pg library defaults to 10, which is too low
|
|
39
|
+
* for applications with many SMRT collections.
|
|
40
|
+
*/
|
|
41
|
+
max?: number;
|
|
42
|
+
/**
|
|
43
|
+
* Schema definitions for tables.
|
|
44
|
+
* Accepts a record or a lazy function (see SchemasOption).
|
|
45
|
+
*
|
|
46
|
+
* **Postgres ignores this option** — tables are managed by migrations.
|
|
47
|
+
* The option exists so callers can pass schemas uniformly to all adapters
|
|
48
|
+
* without knowing the adapter type. Only JSON/DuckDB adapters resolve it.
|
|
49
|
+
*/
|
|
50
|
+
schemas?: import('./shared/types').SchemasOption;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Clears the PostgreSQL connection cache.
|
|
54
|
+
* Useful for test isolation and reconnection scenarios.
|
|
55
|
+
*/
|
|
56
|
+
export declare function clearPostgresConnectionCache(): void;
|
|
57
|
+
/**
|
|
58
|
+
* Creates a PostgreSQL database adapter
|
|
59
|
+
*
|
|
60
|
+
* Loads configuration from environment variables with backward compatibility:
|
|
61
|
+
* - First checks HAVE_SQL_* environment variables (new standard)
|
|
62
|
+
* - Falls back to SQLOO_* environment variables (legacy)
|
|
63
|
+
* - User-provided options always take precedence
|
|
64
|
+
*
|
|
65
|
+
* Environment variables:
|
|
66
|
+
* - HAVE_SQL_URL / SQLOO_URL → Connection string (takes precedence)
|
|
67
|
+
* - HAVE_SQL_DATABASE / SQLOO_DATABASE → Database name
|
|
68
|
+
* - HAVE_SQL_HOST / SQLOO_HOST → Host (default: 'localhost')
|
|
69
|
+
* - HAVE_SQL_USER / SQLOO_USER → Username
|
|
70
|
+
* - HAVE_SQL_PASSWORD / SQLOO_PASSWORD → Password
|
|
71
|
+
* - HAVE_SQL_PORT / SQLOO_PORT → Port (default: 5432)
|
|
72
|
+
*
|
|
73
|
+
* @param options - PostgreSQL connection options
|
|
74
|
+
* @returns Database interface for PostgreSQL
|
|
75
|
+
*/
|
|
76
|
+
export declare function getDatabase(options?: PostgresOptions): Promise<DatabaseInterface>;
|
|
77
|
+
//# sourceMappingURL=postgres.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres.d.ts","sourceRoot":"","sources":["../src/postgres.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAIV,iBAAiB,EAYlB,MAAM,gBAAgB,CAAC;AAGxB;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;;OAIG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb;;;;;;;OAOG;IACH,OAAO,CAAC,EAAE,OAAO,gBAAgB,EAAE,aAAa,CAAC;CAClD;AAiBD;;;GAGG;AACH,wBAAgB,4BAA4B,IAAI,IAAI,CAGnD;AA4YD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,WAAW,CAC/B,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAAC,iBAAiB,CAAC,CA8C5B"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { DatabaseInterface, SchemaInitializationOptions } from './shared/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Result returned by DatabaseSchemaManager.initializeSchemas()
|
|
4
|
+
*
|
|
5
|
+
* Contains the list of schemas that were successfully initialized,
|
|
6
|
+
* any that were skipped (already up to date), errors encountered,
|
|
7
|
+
* and the total execution time in milliseconds.
|
|
8
|
+
*/
|
|
9
|
+
export interface SchemaInitializationResult {
|
|
10
|
+
initialized: string[];
|
|
11
|
+
skipped: string[];
|
|
12
|
+
errors: Array<{
|
|
13
|
+
schema: string;
|
|
14
|
+
error: string;
|
|
15
|
+
}>;
|
|
16
|
+
executionTime: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Manages schema initialization from JSON manifests with dependency resolution
|
|
20
|
+
*
|
|
21
|
+
* Handles topological sorting of schema dependencies, table creation,
|
|
22
|
+
* index and trigger setup, and version tracking to avoid redundant re-initialization.
|
|
23
|
+
*/
|
|
24
|
+
export declare class DatabaseSchemaManager {
|
|
25
|
+
private static initializationLock;
|
|
26
|
+
private initializedSchemas;
|
|
27
|
+
private schemaVersions;
|
|
28
|
+
/**
|
|
29
|
+
* Initializes database schemas from a JSON manifest with dependency resolution
|
|
30
|
+
*
|
|
31
|
+
* Schemas are topologically sorted by their declared dependencies and
|
|
32
|
+
* initialized in order. Supports legacy raw-SQL schemas via the `schema` option,
|
|
33
|
+
* JSON manifests via the `manifest` option, and schema overrides for extending
|
|
34
|
+
* base schemas.
|
|
35
|
+
*
|
|
36
|
+
* @param db - Database interface to execute DDL against
|
|
37
|
+
* @param options - Schema initialization options (manifest, overrides, force, debug)
|
|
38
|
+
* @returns Result with lists of initialized/skipped schemas, errors, and execution time
|
|
39
|
+
*/
|
|
40
|
+
initializeSchemas(db: DatabaseInterface, options: SchemaInitializationOptions): Promise<SchemaInitializationResult>;
|
|
41
|
+
/**
|
|
42
|
+
* Initialize a single schema
|
|
43
|
+
*/
|
|
44
|
+
private initializeSchema;
|
|
45
|
+
/**
|
|
46
|
+
* Perform the actual schema initialization
|
|
47
|
+
*/
|
|
48
|
+
private performSchemaInitialization;
|
|
49
|
+
/**
|
|
50
|
+
* Create table from schema definition
|
|
51
|
+
*/
|
|
52
|
+
private createTable;
|
|
53
|
+
/**
|
|
54
|
+
* Create index from definition
|
|
55
|
+
*/
|
|
56
|
+
private createIndex;
|
|
57
|
+
/**
|
|
58
|
+
* Create trigger from definition
|
|
59
|
+
*/
|
|
60
|
+
private createTrigger;
|
|
61
|
+
/**
|
|
62
|
+
* Update schema if changes are detected
|
|
63
|
+
*/
|
|
64
|
+
private updateSchemaIfNeeded;
|
|
65
|
+
/**
|
|
66
|
+
* Build dependency graph from schemas
|
|
67
|
+
*/
|
|
68
|
+
private buildDependencyGraph;
|
|
69
|
+
/**
|
|
70
|
+
* Resolve dependencies using topological sort
|
|
71
|
+
*/
|
|
72
|
+
private resolveDependencies;
|
|
73
|
+
/**
|
|
74
|
+
* Check if schema is up to date
|
|
75
|
+
*/
|
|
76
|
+
private isSchemaUpToDate;
|
|
77
|
+
/**
|
|
78
|
+
* Mark schema as initialized
|
|
79
|
+
*/
|
|
80
|
+
private markSchemaInitialized;
|
|
81
|
+
/**
|
|
82
|
+
* Reset initialization state (for testing)
|
|
83
|
+
*/
|
|
84
|
+
reset(): void;
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=schema-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-manager.d.ts","sourceRoot":"","sources":["../src/schema-manager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACV,iBAAiB,EAGjB,2BAA2B,EAE5B,MAAM,mBAAmB,CAAC;AAE3B;;;;;;GAMG;AACH,MAAM,WAAW,0BAA0B;IACzC,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,MAAM,EAAE,KAAK,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACjD,aAAa,EAAE,MAAM,CAAC;CACvB;AAED;;;;;GAKG;AACH,qBAAa,qBAAqB;IAChC,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAAoC;IACrE,OAAO,CAAC,kBAAkB,CAAqB;IAC/C,OAAO,CAAC,cAAc,CAA6B;IAEnD;;;;;;;;;;;OAWG;IACG,iBAAiB,CACrB,EAAE,EAAE,iBAAiB,EACrB,OAAO,EAAE,2BAA2B,GACnC,OAAO,CAAC,0BAA0B,CAAC;IAgGtC;;OAEG;YACW,gBAAgB;IAwC9B;;OAEG;YACW,2BAA2B;IA8CzC;;OAEG;YACW,WAAW;IAmCzB;;OAEG;YACW,WAAW;IAYzB;;OAEG;YACW,aAAa;IAY3B;;OAEG;YACW,oBAAoB;IAWlC;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAuB5B;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAkC3B;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAOxB;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAK7B;;OAEG;IACH,KAAK,IAAI,IAAI;CAKd"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { ColumnDefinitionWithName, IndexDefinition } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Database dialect type for SQL generation
|
|
4
|
+
*/
|
|
5
|
+
export type DatabaseDialect = 'sqlite' | 'postgres' | 'duckdb';
|
|
6
|
+
/**
|
|
7
|
+
* Generates an ALTER TABLE ADD COLUMN statement
|
|
8
|
+
*
|
|
9
|
+
* @param table - Table name
|
|
10
|
+
* @param column - Column definition with name
|
|
11
|
+
* @param dialect - Database dialect
|
|
12
|
+
* @returns SQL statement string
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const sql = generateAddColumnStatement('users', {
|
|
17
|
+
* name: 'email',
|
|
18
|
+
* type: 'TEXT',
|
|
19
|
+
* unique: true,
|
|
20
|
+
* notNull: false
|
|
21
|
+
* }, 'sqlite');
|
|
22
|
+
* // Returns: "ALTER TABLE users ADD COLUMN email TEXT UNIQUE"
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare function generateAddColumnStatement(table: string, column: ColumnDefinitionWithName, _dialect: DatabaseDialect): string;
|
|
26
|
+
/**
|
|
27
|
+
* Generates a DEFAULT clause for a column definition
|
|
28
|
+
*
|
|
29
|
+
* Handles proper formatting and escaping of default values based on column type.
|
|
30
|
+
*
|
|
31
|
+
* @param columnType - SQL column type (TEXT, INTEGER, BOOLEAN, etc.)
|
|
32
|
+
* @param defaultValue - Default value to format
|
|
33
|
+
* @returns Formatted default value string
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* generateDefaultClause('TEXT', 'hello'); // Returns: "'hello'"
|
|
38
|
+
* generateDefaultClause('INTEGER', 42); // Returns: "42"
|
|
39
|
+
* generateDefaultClause('BOOLEAN', true); // Returns: "true"
|
|
40
|
+
* generateDefaultClause('TEXT', null); // Returns: "NULL"
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare function generateDefaultClause(columnType: string, defaultValue: any): string;
|
|
44
|
+
/**
|
|
45
|
+
* Generates a CREATE INDEX statement
|
|
46
|
+
*
|
|
47
|
+
* @param table - Table name
|
|
48
|
+
* @param index - Index definition
|
|
49
|
+
* @returns SQL CREATE INDEX statement
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* const sql = generateCreateIndexStatement('users', {
|
|
54
|
+
* name: 'idx_users_email',
|
|
55
|
+
* columns: ['email'],
|
|
56
|
+
* unique: true
|
|
57
|
+
* });
|
|
58
|
+
* // Returns: "CREATE UNIQUE INDEX idx_users_email ON users (email)"
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export declare function generateCreateIndexStatement(table: string, index: IndexDefinition): string;
|
|
62
|
+
/**
|
|
63
|
+
* Validates a table name to prevent SQL injection
|
|
64
|
+
*
|
|
65
|
+
* @param tableName - Table name to validate
|
|
66
|
+
* @throws Error if table name contains invalid characters
|
|
67
|
+
*/
|
|
68
|
+
export declare function validateTableName(tableName: string): void;
|
|
69
|
+
/**
|
|
70
|
+
* Validates a column name to prevent SQL injection
|
|
71
|
+
*
|
|
72
|
+
* @param columnName - Column name to validate
|
|
73
|
+
* @throws Error if column name contains invalid characters
|
|
74
|
+
*/
|
|
75
|
+
export declare function validateColumnName(columnName: string): void;
|
|
76
|
+
/**
|
|
77
|
+
* Validates an index name to prevent SQL injection
|
|
78
|
+
*
|
|
79
|
+
* @param indexName - Index name to validate
|
|
80
|
+
* @throws Error if index name contains invalid characters
|
|
81
|
+
*/
|
|
82
|
+
export declare function validateIndexName(indexName: string): void;
|
|
83
|
+
//# sourceMappingURL=alter-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"alter-utils.d.ts","sourceRoot":"","sources":["../../src/shared/alter-utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,wBAAwB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE5E;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,QAAQ,GAAG,UAAU,GAAG,QAAQ,CAAC;AAE/D;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,wBAAwB,EAChC,QAAQ,EAAE,eAAe,GACxB,MAAM,CAkDR;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,qBAAqB,CACnC,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,GAAG,GAChB,MAAM,CAkER;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,4BAA4B,CAC1C,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,eAAe,GACrB,MAAM,CA0BR;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAMzD;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAM3D;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAMzD"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DuckDB-specific schema transformation utilities
|
|
3
|
+
*
|
|
4
|
+
* DuckDB has a known limitation (issue #12684) where ON CONFLICT clauses
|
|
5
|
+
* fail with UNIQUE INDEX but work with inline UNIQUE constraints.
|
|
6
|
+
*
|
|
7
|
+
* This module provides utilities to transform SMRT-generated schemas
|
|
8
|
+
* (which use separate CREATE UNIQUE INDEX statements) into DuckDB-compatible
|
|
9
|
+
* schemas (which use inline UNIQUE constraints).
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Index definition extracted from CREATE INDEX statement
|
|
13
|
+
*/
|
|
14
|
+
interface ParsedIndex {
|
|
15
|
+
name: string;
|
|
16
|
+
columns: string[];
|
|
17
|
+
unique: boolean;
|
|
18
|
+
sql: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Parses a CREATE INDEX statement to extract index details
|
|
22
|
+
*
|
|
23
|
+
* @param indexSQL - CREATE INDEX statement
|
|
24
|
+
* @returns Parsed index definition or null if parsing fails
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* const index = parseIndexStatement(
|
|
29
|
+
* 'CREATE UNIQUE INDEX ds_slug_context_idx ON ds (slug, context)'
|
|
30
|
+
* );
|
|
31
|
+
* // Returns: {
|
|
32
|
+
* // name: 'ds_slug_context_idx',
|
|
33
|
+
* // columns: ['slug', 'context'],
|
|
34
|
+
* // unique: true,
|
|
35
|
+
* // sql: '...'
|
|
36
|
+
* // }
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare function parseIndexStatement(indexSQL: string): ParsedIndex | null;
|
|
40
|
+
/**
|
|
41
|
+
* Converts UNIQUE INDEX statements to inline UNIQUE constraints for DuckDB compatibility
|
|
42
|
+
*
|
|
43
|
+
* DuckDB's ON CONFLICT clause requires inline UNIQUE constraints, not separate indexes.
|
|
44
|
+
* This function transforms SMRT-generated schemas to work with DuckDB's limitations.
|
|
45
|
+
*
|
|
46
|
+
* @param ddl - CREATE TABLE DDL statement
|
|
47
|
+
* @param indexes - Array of CREATE INDEX statements (optional)
|
|
48
|
+
* @returns Transformed DDL with inline UNIQUE constraints and filtered index list
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* const ddl = `
|
|
53
|
+
* CREATE TABLE ds (
|
|
54
|
+
* id TEXT PRIMARY KEY,
|
|
55
|
+
* slug TEXT NOT NULL,
|
|
56
|
+
* context TEXT NOT NULL
|
|
57
|
+
* )
|
|
58
|
+
* `;
|
|
59
|
+
* const indexes = [
|
|
60
|
+
* 'CREATE UNIQUE INDEX ds_slug_context_idx ON ds (slug, context)'
|
|
61
|
+
* ];
|
|
62
|
+
*
|
|
63
|
+
* const result = convertUniqueIndexesToInlineConstraints(ddl, indexes);
|
|
64
|
+
* // result.ddl:
|
|
65
|
+
* // CREATE TABLE ds (
|
|
66
|
+
* // id TEXT PRIMARY KEY,
|
|
67
|
+
* // slug TEXT NOT NULL,
|
|
68
|
+
* // context TEXT NOT NULL,
|
|
69
|
+
* // UNIQUE(slug, context)
|
|
70
|
+
* // )
|
|
71
|
+
* // result.indexes: [] (UNIQUE index removed, non-UNIQUE indexes preserved)
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export declare function convertUniqueIndexesToInlineConstraints(ddl: string, indexes?: string[]): {
|
|
75
|
+
ddl: string;
|
|
76
|
+
indexes: string[];
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Checks if a schema definition contains UNIQUE indexes that need conversion
|
|
80
|
+
*
|
|
81
|
+
* @param indexes - Array of CREATE INDEX statements
|
|
82
|
+
* @returns True if any UNIQUE indexes are present
|
|
83
|
+
*/
|
|
84
|
+
export declare function hasUniqueIndexes(indexes?: string[]): boolean;
|
|
85
|
+
export {};
|
|
86
|
+
//# sourceMappingURL=duckdb-schema-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"duckdb-schema-utils.d.ts","sourceRoot":"","sources":["../../src/shared/duckdb-schema-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH;;GAEG;AACH,UAAU,WAAW;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,MAAM,EAAE,OAAO,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;CACb;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI,CA0BxE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,uCAAuC,CACrD,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,MAAM,EAAE,GACjB;IACD,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB,CA4EA;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,CAS5D"}
|