@nextlyhq/adapter-drizzle 0.0.1
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/LICENSE +22 -0
- package/README.md +9 -0
- package/dist/adapter-BxJVtttb.d.ts +592 -0
- package/dist/adapter-nvlxFkF-.d.cts +592 -0
- package/dist/core-CVO7WYDj.d.cts +74 -0
- package/dist/core-CVO7WYDj.d.ts +74 -0
- package/dist/error-um1d_3Uo.d.cts +105 -0
- package/dist/error-um1d_3Uo.d.ts +105 -0
- package/dist/index.cjs +1137 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +57 -0
- package/dist/index.d.ts +57 -0
- package/dist/index.mjs +1134 -0
- package/dist/index.mjs.map +1 -0
- package/dist/migration-BbO5meEV.d.cts +622 -0
- package/dist/migration-Qe70wDOC.d.ts +622 -0
- package/dist/migrations.cjs +195 -0
- package/dist/migrations.cjs.map +1 -0
- package/dist/migrations.d.cts +351 -0
- package/dist/migrations.d.ts +351 -0
- package/dist/migrations.mjs +185 -0
- package/dist/migrations.mjs.map +1 -0
- package/dist/schema/index.cjs +10 -0
- package/dist/schema/index.cjs.map +1 -0
- package/dist/schema/index.d.cts +133 -0
- package/dist/schema/index.d.ts +133 -0
- package/dist/schema/index.mjs +7 -0
- package/dist/schema/index.mjs.map +1 -0
- package/dist/schema-BDn8WfSL.d.cts +200 -0
- package/dist/schema-BIQ0YQZ_.d.ts +200 -0
- package/dist/types/index.cjs +24 -0
- package/dist/types/index.cjs.map +1 -0
- package/dist/types/index.d.cts +210 -0
- package/dist/types/index.d.ts +210 -0
- package/dist/types/index.mjs +21 -0
- package/dist/types/index.mjs.map +1 -0
- package/dist/version-check.cjs +154 -0
- package/dist/version-check.cjs.map +1 -0
- package/dist/version-check.d.cts +43 -0
- package/dist/version-check.d.ts +43 -0
- package/dist/version-check.mjs +150 -0
- package/dist/version-check.mjs.map +1 -0
- package/package.json +94 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
export { A as AlterTableOperation, a as AlterTableOptions, b as ColumnDefinition, C as CreateTableOptions, D as DropTableOptions, I as IndexDefinition, c as TableConstraint, T as TableDefinition } from '../schema-BDn8WfSL.cjs';
|
|
2
|
+
export { a as SqlParam } from '../core-CVO7WYDj.cjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Schema utilities for @nextly/adapter-drizzle
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* This module re-exports schema-related types from the `/types` subpath
|
|
9
|
+
*
|
|
10
|
+
* ## Current Exports
|
|
11
|
+
*
|
|
12
|
+
* - **Schema Type Definitions:** {@link TableDefinition}, {@link ColumnDefinition}, {@link IndexDefinition}, {@link TableConstraint}
|
|
13
|
+
* - **Schema Operation Types:** {@link CreateTableOptions}, {@link DropTableOptions}, {@link AlterTableOptions}, {@link AlterTableOperation}
|
|
14
|
+
* - **Core Types:** {@link SqlParam}
|
|
15
|
+
*
|
|
16
|
+
* ## Coming in Phase 4
|
|
17
|
+
*
|
|
18
|
+
* - Schema builder utilities
|
|
19
|
+
* - Schema generator functions
|
|
20
|
+
* - Dialect-specific schema mapping
|
|
21
|
+
* - Unified schema definitions
|
|
22
|
+
*
|
|
23
|
+
* ## Usage Examples
|
|
24
|
+
*
|
|
25
|
+
* ### Defining a Table Schema
|
|
26
|
+
*
|
|
27
|
+
* ```typescript
|
|
28
|
+
* import type { TableDefinition } from "@nextly/adapter-drizzle/schema";
|
|
29
|
+
*
|
|
30
|
+
* const usersTable: TableDefinition = {
|
|
31
|
+
* name: "users",
|
|
32
|
+
* columns: [
|
|
33
|
+
* { name: "id", type: "uuid", primaryKey: true },
|
|
34
|
+
* { name: "email", type: "varchar(255)", unique: true },
|
|
35
|
+
* { name: "name", type: "varchar(255)", nullable: true },
|
|
36
|
+
* {
|
|
37
|
+
* name: "created_at",
|
|
38
|
+
* type: "timestamp",
|
|
39
|
+
* default: { sql: "CURRENT_TIMESTAMP" },
|
|
40
|
+
* },
|
|
41
|
+
* ],
|
|
42
|
+
* indexes: [
|
|
43
|
+
* { name: "users_email_idx", columns: ["email"], unique: true },
|
|
44
|
+
* ],
|
|
45
|
+
* };
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* ### Creating a Table with Adapter
|
|
49
|
+
*
|
|
50
|
+
* ```typescript
|
|
51
|
+
* import type { DrizzleAdapter } from "@nextly/adapter-drizzle";
|
|
52
|
+
* import type { TableDefinition } from "@nextly/adapter-drizzle/schema";
|
|
53
|
+
*
|
|
54
|
+
* async function createUsersTable(adapter: DrizzleAdapter) {
|
|
55
|
+
* const tableDefinition: TableDefinition = {
|
|
56
|
+
* // ... table definition
|
|
57
|
+
* };
|
|
58
|
+
*
|
|
59
|
+
* await adapter.createTable(tableDefinition, { ifNotExists: true });
|
|
60
|
+
* }
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* ### Altering a Table
|
|
64
|
+
*
|
|
65
|
+
* ```typescript
|
|
66
|
+
* import type {
|
|
67
|
+
* AlterTableOperation,
|
|
68
|
+
* ColumnDefinition,
|
|
69
|
+
* } from "@nextly/adapter-drizzle/schema";
|
|
70
|
+
*
|
|
71
|
+
* const operations: AlterTableOperation[] = [
|
|
72
|
+
* {
|
|
73
|
+
* kind: "add_column",
|
|
74
|
+
* column: { name: "age", type: "int", nullable: true },
|
|
75
|
+
* },
|
|
76
|
+
* {
|
|
77
|
+
* kind: "rename_column",
|
|
78
|
+
* from: "name",
|
|
79
|
+
* to: "full_name",
|
|
80
|
+
* },
|
|
81
|
+
* ];
|
|
82
|
+
*
|
|
83
|
+
* await adapter.alterTable("users", operations);
|
|
84
|
+
* ```
|
|
85
|
+
*
|
|
86
|
+
* @packageDocumentation
|
|
87
|
+
*/
|
|
88
|
+
/**
|
|
89
|
+
* Column definition for schema operations.
|
|
90
|
+
*
|
|
91
|
+
* @remarks
|
|
92
|
+
* Defines the structure of a database column in a database-agnostic way.
|
|
93
|
+
* Adapters translate these definitions to dialect-specific DDL.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* const idColumn: ColumnDefinition = {
|
|
98
|
+
* name: "id",
|
|
99
|
+
* type: "uuid",
|
|
100
|
+
* primaryKey: true,
|
|
101
|
+
* };
|
|
102
|
+
*
|
|
103
|
+
* const emailColumn: ColumnDefinition = {
|
|
104
|
+
* name: "email",
|
|
105
|
+
* type: "varchar(255)",
|
|
106
|
+
* unique: true,
|
|
107
|
+
* };
|
|
108
|
+
* ```
|
|
109
|
+
*
|
|
110
|
+
* @public
|
|
111
|
+
*/
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Schema utilities version.
|
|
115
|
+
*
|
|
116
|
+
* @remarks
|
|
117
|
+
* This version tracks the schema utilities module independently
|
|
118
|
+
* from the main adapter package version.
|
|
119
|
+
*
|
|
120
|
+
* @internal
|
|
121
|
+
*/
|
|
122
|
+
declare const SCHEMA_VERSION: "0.1.0";
|
|
123
|
+
/**
|
|
124
|
+
* Indicates whether schema builder utilities are available.
|
|
125
|
+
*
|
|
126
|
+
* @remarks
|
|
127
|
+
* Currently `false` - schema builder utilities will be implemented
|
|
128
|
+
*
|
|
129
|
+
* @internal
|
|
130
|
+
*/
|
|
131
|
+
declare const SCHEMA_BUILDER_AVAILABLE: false;
|
|
132
|
+
|
|
133
|
+
export { SCHEMA_BUILDER_AVAILABLE, SCHEMA_VERSION };
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
export { A as AlterTableOperation, a as AlterTableOptions, b as ColumnDefinition, C as CreateTableOptions, D as DropTableOptions, I as IndexDefinition, c as TableConstraint, T as TableDefinition } from '../schema-BIQ0YQZ_.js';
|
|
2
|
+
export { a as SqlParam } from '../core-CVO7WYDj.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Schema utilities for @nextly/adapter-drizzle
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* This module re-exports schema-related types from the `/types` subpath
|
|
9
|
+
*
|
|
10
|
+
* ## Current Exports
|
|
11
|
+
*
|
|
12
|
+
* - **Schema Type Definitions:** {@link TableDefinition}, {@link ColumnDefinition}, {@link IndexDefinition}, {@link TableConstraint}
|
|
13
|
+
* - **Schema Operation Types:** {@link CreateTableOptions}, {@link DropTableOptions}, {@link AlterTableOptions}, {@link AlterTableOperation}
|
|
14
|
+
* - **Core Types:** {@link SqlParam}
|
|
15
|
+
*
|
|
16
|
+
* ## Coming in Phase 4
|
|
17
|
+
*
|
|
18
|
+
* - Schema builder utilities
|
|
19
|
+
* - Schema generator functions
|
|
20
|
+
* - Dialect-specific schema mapping
|
|
21
|
+
* - Unified schema definitions
|
|
22
|
+
*
|
|
23
|
+
* ## Usage Examples
|
|
24
|
+
*
|
|
25
|
+
* ### Defining a Table Schema
|
|
26
|
+
*
|
|
27
|
+
* ```typescript
|
|
28
|
+
* import type { TableDefinition } from "@nextly/adapter-drizzle/schema";
|
|
29
|
+
*
|
|
30
|
+
* const usersTable: TableDefinition = {
|
|
31
|
+
* name: "users",
|
|
32
|
+
* columns: [
|
|
33
|
+
* { name: "id", type: "uuid", primaryKey: true },
|
|
34
|
+
* { name: "email", type: "varchar(255)", unique: true },
|
|
35
|
+
* { name: "name", type: "varchar(255)", nullable: true },
|
|
36
|
+
* {
|
|
37
|
+
* name: "created_at",
|
|
38
|
+
* type: "timestamp",
|
|
39
|
+
* default: { sql: "CURRENT_TIMESTAMP" },
|
|
40
|
+
* },
|
|
41
|
+
* ],
|
|
42
|
+
* indexes: [
|
|
43
|
+
* { name: "users_email_idx", columns: ["email"], unique: true },
|
|
44
|
+
* ],
|
|
45
|
+
* };
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* ### Creating a Table with Adapter
|
|
49
|
+
*
|
|
50
|
+
* ```typescript
|
|
51
|
+
* import type { DrizzleAdapter } from "@nextly/adapter-drizzle";
|
|
52
|
+
* import type { TableDefinition } from "@nextly/adapter-drizzle/schema";
|
|
53
|
+
*
|
|
54
|
+
* async function createUsersTable(adapter: DrizzleAdapter) {
|
|
55
|
+
* const tableDefinition: TableDefinition = {
|
|
56
|
+
* // ... table definition
|
|
57
|
+
* };
|
|
58
|
+
*
|
|
59
|
+
* await adapter.createTable(tableDefinition, { ifNotExists: true });
|
|
60
|
+
* }
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* ### Altering a Table
|
|
64
|
+
*
|
|
65
|
+
* ```typescript
|
|
66
|
+
* import type {
|
|
67
|
+
* AlterTableOperation,
|
|
68
|
+
* ColumnDefinition,
|
|
69
|
+
* } from "@nextly/adapter-drizzle/schema";
|
|
70
|
+
*
|
|
71
|
+
* const operations: AlterTableOperation[] = [
|
|
72
|
+
* {
|
|
73
|
+
* kind: "add_column",
|
|
74
|
+
* column: { name: "age", type: "int", nullable: true },
|
|
75
|
+
* },
|
|
76
|
+
* {
|
|
77
|
+
* kind: "rename_column",
|
|
78
|
+
* from: "name",
|
|
79
|
+
* to: "full_name",
|
|
80
|
+
* },
|
|
81
|
+
* ];
|
|
82
|
+
*
|
|
83
|
+
* await adapter.alterTable("users", operations);
|
|
84
|
+
* ```
|
|
85
|
+
*
|
|
86
|
+
* @packageDocumentation
|
|
87
|
+
*/
|
|
88
|
+
/**
|
|
89
|
+
* Column definition for schema operations.
|
|
90
|
+
*
|
|
91
|
+
* @remarks
|
|
92
|
+
* Defines the structure of a database column in a database-agnostic way.
|
|
93
|
+
* Adapters translate these definitions to dialect-specific DDL.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* const idColumn: ColumnDefinition = {
|
|
98
|
+
* name: "id",
|
|
99
|
+
* type: "uuid",
|
|
100
|
+
* primaryKey: true,
|
|
101
|
+
* };
|
|
102
|
+
*
|
|
103
|
+
* const emailColumn: ColumnDefinition = {
|
|
104
|
+
* name: "email",
|
|
105
|
+
* type: "varchar(255)",
|
|
106
|
+
* unique: true,
|
|
107
|
+
* };
|
|
108
|
+
* ```
|
|
109
|
+
*
|
|
110
|
+
* @public
|
|
111
|
+
*/
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Schema utilities version.
|
|
115
|
+
*
|
|
116
|
+
* @remarks
|
|
117
|
+
* This version tracks the schema utilities module independently
|
|
118
|
+
* from the main adapter package version.
|
|
119
|
+
*
|
|
120
|
+
* @internal
|
|
121
|
+
*/
|
|
122
|
+
declare const SCHEMA_VERSION: "0.1.0";
|
|
123
|
+
/**
|
|
124
|
+
* Indicates whether schema builder utilities are available.
|
|
125
|
+
*
|
|
126
|
+
* @remarks
|
|
127
|
+
* Currently `false` - schema builder utilities will be implemented
|
|
128
|
+
*
|
|
129
|
+
* @internal
|
|
130
|
+
*/
|
|
131
|
+
declare const SCHEMA_BUILDER_AVAILABLE: false;
|
|
132
|
+
|
|
133
|
+
export { SCHEMA_BUILDER_AVAILABLE, SCHEMA_VERSION };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/schema/index.ts"],"names":[],"mappings":";AAuRO,IAAM,cAAA,GAAiB;AAUvB,IAAM,wBAAA,GAA2B","file":"index.mjs","sourcesContent":["/**\n * Schema utilities for @nextly/adapter-drizzle\n *\n * @remarks\n * This module re-exports schema-related types from the `/types` subpath\n *\n * ## Current Exports\n *\n * - **Schema Type Definitions:** {@link TableDefinition}, {@link ColumnDefinition}, {@link IndexDefinition}, {@link TableConstraint}\n * - **Schema Operation Types:** {@link CreateTableOptions}, {@link DropTableOptions}, {@link AlterTableOptions}, {@link AlterTableOperation}\n * - **Core Types:** {@link SqlParam}\n *\n * ## Coming in Phase 4\n *\n * - Schema builder utilities\n * - Schema generator functions\n * - Dialect-specific schema mapping\n * - Unified schema definitions\n *\n * ## Usage Examples\n *\n * ### Defining a Table Schema\n *\n * ```typescript\n * import type { TableDefinition } from \"@nextly/adapter-drizzle/schema\";\n *\n * const usersTable: TableDefinition = {\n * name: \"users\",\n * columns: [\n * { name: \"id\", type: \"uuid\", primaryKey: true },\n * { name: \"email\", type: \"varchar(255)\", unique: true },\n * { name: \"name\", type: \"varchar(255)\", nullable: true },\n * {\n * name: \"created_at\",\n * type: \"timestamp\",\n * default: { sql: \"CURRENT_TIMESTAMP\" },\n * },\n * ],\n * indexes: [\n * { name: \"users_email_idx\", columns: [\"email\"], unique: true },\n * ],\n * };\n * ```\n *\n * ### Creating a Table with Adapter\n *\n * ```typescript\n * import type { DrizzleAdapter } from \"@nextly/adapter-drizzle\";\n * import type { TableDefinition } from \"@nextly/adapter-drizzle/schema\";\n *\n * async function createUsersTable(adapter: DrizzleAdapter) {\n * const tableDefinition: TableDefinition = {\n * // ... table definition\n * };\n *\n * await adapter.createTable(tableDefinition, { ifNotExists: true });\n * }\n * ```\n *\n * ### Altering a Table\n *\n * ```typescript\n * import type {\n * AlterTableOperation,\n * ColumnDefinition,\n * } from \"@nextly/adapter-drizzle/schema\";\n *\n * const operations: AlterTableOperation[] = [\n * {\n * kind: \"add_column\",\n * column: { name: \"age\", type: \"int\", nullable: true },\n * },\n * {\n * kind: \"rename_column\",\n * from: \"name\",\n * to: \"full_name\",\n * },\n * ];\n *\n * await adapter.alterTable(\"users\", operations);\n * ```\n *\n * @packageDocumentation\n */\n\n// ============================================================\n// Schema Type Re-exports\n// ============================================================\n\n/**\n * Column definition for schema operations.\n *\n * @remarks\n * Defines the structure of a database column in a database-agnostic way.\n * Adapters translate these definitions to dialect-specific DDL.\n *\n * @example\n * ```typescript\n * const idColumn: ColumnDefinition = {\n * name: \"id\",\n * type: \"uuid\",\n * primaryKey: true,\n * };\n *\n * const emailColumn: ColumnDefinition = {\n * name: \"email\",\n * type: \"varchar(255)\",\n * unique: true,\n * };\n * ```\n *\n * @public\n */\nexport type { ColumnDefinition } from \"../types/schema\";\n\n/**\n * Index definition for schema operations.\n *\n * @remarks\n * Defines database indexes for performance optimization.\n *\n * @example\n * ```typescript\n * const emailIndex: IndexDefinition = {\n * name: \"users_email_idx\",\n * columns: [\"email\"],\n * unique: true,\n * };\n * ```\n *\n * @public\n */\nexport type { IndexDefinition } from \"../types/schema\";\n\n/**\n * Table constraint definition.\n *\n * @example\n * ```typescript\n * const checkConstraint: TableConstraint = {\n * name: \"check_age_positive\",\n * type: \"check\",\n * expression: \"age >= 0\",\n * };\n * ```\n *\n * @public\n */\nexport type { TableConstraint } from \"../types/schema\";\n\n/**\n * Complete table definition.\n *\n * @remarks\n * Defines the complete structure of a database table including columns,\n * indexes, and constraints.\n *\n * @example\n * ```typescript\n * const postsTable: TableDefinition = {\n * name: \"posts\",\n * columns: [\n * { name: \"id\", type: \"uuid\", primaryKey: true },\n * { name: \"title\", type: \"varchar(255)\" },\n * { name: \"content\", type: \"text\" },\n * { name: \"published\", type: \"boolean\", default: false },\n * ],\n * indexes: [\n * { name: \"posts_title_idx\", columns: [\"title\"] },\n * ],\n * };\n * ```\n *\n * @public\n */\nexport type { TableDefinition } from \"../types/schema\";\n\n/**\n * Options for table creation.\n *\n * @example\n * ```typescript\n * const options: CreateTableOptions = {\n * ifNotExists: true,\n * temporary: false,\n * };\n *\n * await adapter.createTable(tableDefinition, options);\n * ```\n *\n * @public\n */\nexport type { CreateTableOptions } from \"../types/schema\";\n\n/**\n * Options for table dropping.\n *\n * @example\n * ```typescript\n * const options: DropTableOptions = {\n * ifExists: true,\n * cascade: true,\n * };\n *\n * await adapter.dropTable(\"old_table\", options);\n * ```\n *\n * @public\n */\nexport type { DropTableOptions } from \"../types/schema\";\n\n/**\n * Options for table alteration.\n *\n * @public\n */\nexport type { AlterTableOptions } from \"../types/schema\";\n\n/**\n * Table alteration operations.\n *\n * @remarks\n * Defines the types of operations that can be performed when altering a table.\n *\n * @example\n * ```typescript\n * const operations: AlterTableOperation[] = [\n * {\n * kind: \"add_column\",\n * column: { name: \"status\", type: \"varchar(20)\", default: \"draft\" },\n * },\n * {\n * kind: \"drop_column\",\n * columnName: \"old_field\",\n * },\n * {\n * kind: \"add_constraint\",\n * constraint: {\n * name: \"check_status\",\n * type: \"check\",\n * expression: \"status IN ('draft', 'published')\",\n * },\n * },\n * ];\n *\n * await adapter.alterTable(\"posts\", operations);\n * ```\n *\n * @public\n */\nexport type { AlterTableOperation } from \"../types/schema\";\n\n// ============================================================\n// Core Type Re-exports\n// ============================================================\n\n/**\n * SQL parameter type (for use in column defaults, etc.).\n *\n * @remarks\n * Represents values that can be safely passed as SQL parameters.\n *\n * @public\n */\nexport type { SqlParam } from \"../types/core\";\n\n// ============================================================\n// Module Metadata\n// ============================================================\n\n/**\n * Schema utilities version.\n *\n * @remarks\n * This version tracks the schema utilities module independently\n * from the main adapter package version.\n *\n * @internal\n */\nexport const SCHEMA_VERSION = \"0.1.0\" as const;\n\n/**\n * Indicates whether schema builder utilities are available.\n *\n * @remarks\n * Currently `false` - schema builder utilities will be implemented\n *\n * @internal\n */\nexport const SCHEMA_BUILDER_AVAILABLE = false as const;\n"]}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { a as SqlParam } from './core-CVO7WYDj.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Database schema type definitions.
|
|
5
|
+
*
|
|
6
|
+
* @packageDocumentation
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Column definition for schema operations.
|
|
11
|
+
*
|
|
12
|
+
* @remarks
|
|
13
|
+
* Defines the structure of a database column in a database-agnostic way.
|
|
14
|
+
* Adapters translate these definitions to dialect-specific DDL.
|
|
15
|
+
*
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
interface ColumnDefinition {
|
|
19
|
+
/** Column name */
|
|
20
|
+
name: string;
|
|
21
|
+
/**
|
|
22
|
+
* Column data type.
|
|
23
|
+
*
|
|
24
|
+
* @remarks
|
|
25
|
+
* Common types across databases:
|
|
26
|
+
* - Text: varchar(n), text, char(n)
|
|
27
|
+
* - Numbers: int, bigint, decimal, numeric
|
|
28
|
+
* - Boolean: boolean
|
|
29
|
+
* - Date/Time: timestamp, date, time
|
|
30
|
+
* - JSON: json, jsonb (PostgreSQL)
|
|
31
|
+
* - UUID: uuid (PostgreSQL), char(36) (MySQL/SQLite)
|
|
32
|
+
*
|
|
33
|
+
* Adapters handle dialect-specific type mapping.
|
|
34
|
+
*/
|
|
35
|
+
type: string;
|
|
36
|
+
/** Allow NULL values (default: true) */
|
|
37
|
+
nullable?: boolean;
|
|
38
|
+
/** Primary key column */
|
|
39
|
+
primaryKey?: boolean;
|
|
40
|
+
/** Unique constraint */
|
|
41
|
+
unique?: boolean;
|
|
42
|
+
/** Default value (literal or SQL expression) */
|
|
43
|
+
default?: SqlParam | {
|
|
44
|
+
sql: string;
|
|
45
|
+
};
|
|
46
|
+
/** Foreign key reference */
|
|
47
|
+
references?: {
|
|
48
|
+
/** Referenced table name */
|
|
49
|
+
table: string;
|
|
50
|
+
/** Referenced column name */
|
|
51
|
+
column: string;
|
|
52
|
+
/** Action on DELETE */
|
|
53
|
+
onDelete?: "no action" | "restrict" | "cascade" | "set null" | "set default";
|
|
54
|
+
/** Action on UPDATE */
|
|
55
|
+
onUpdate?: "no action" | "restrict" | "cascade" | "set null" | "set default";
|
|
56
|
+
};
|
|
57
|
+
/** Check constraint expression */
|
|
58
|
+
check?: string;
|
|
59
|
+
/** Generated column definition (computed column) */
|
|
60
|
+
generated?: {
|
|
61
|
+
/** SQL expression to generate the value */
|
|
62
|
+
as: string;
|
|
63
|
+
/** Store the value (true) or compute on-the-fly (false) */
|
|
64
|
+
stored?: boolean;
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Index definition for schema operations.
|
|
69
|
+
*
|
|
70
|
+
* @remarks
|
|
71
|
+
* Defines database indexes for performance optimization.
|
|
72
|
+
*
|
|
73
|
+
* @public
|
|
74
|
+
*/
|
|
75
|
+
interface IndexDefinition {
|
|
76
|
+
/** Index name */
|
|
77
|
+
name: string;
|
|
78
|
+
/** Columns included in the index */
|
|
79
|
+
columns: string[];
|
|
80
|
+
/** Unique index (enforces uniqueness) */
|
|
81
|
+
unique?: boolean;
|
|
82
|
+
/** Partial index condition (WHERE clause) */
|
|
83
|
+
where?: string;
|
|
84
|
+
/** Index type (database-specific) */
|
|
85
|
+
using?: "btree" | "hash" | "gin" | "gist" | "brin";
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Table constraint definition.
|
|
89
|
+
*
|
|
90
|
+
* @public
|
|
91
|
+
*/
|
|
92
|
+
interface TableConstraint {
|
|
93
|
+
/** Constraint name */
|
|
94
|
+
name: string;
|
|
95
|
+
/** Constraint type */
|
|
96
|
+
type: "unique" | "check" | "foreign_key" | "primary_key";
|
|
97
|
+
/** Columns involved in the constraint */
|
|
98
|
+
columns?: string[];
|
|
99
|
+
/** Check constraint expression */
|
|
100
|
+
expression?: string;
|
|
101
|
+
/** Foreign key reference (for foreign_key type) */
|
|
102
|
+
references?: {
|
|
103
|
+
/** Referenced table name */
|
|
104
|
+
table: string;
|
|
105
|
+
/** Referenced columns */
|
|
106
|
+
columns: string[];
|
|
107
|
+
/** Action on DELETE */
|
|
108
|
+
onDelete?: "no action" | "restrict" | "cascade" | "set null" | "set default";
|
|
109
|
+
/** Action on UPDATE */
|
|
110
|
+
onUpdate?: "no action" | "restrict" | "cascade" | "set null" | "set default";
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Complete table definition.
|
|
115
|
+
*
|
|
116
|
+
* @remarks
|
|
117
|
+
* Defines the complete structure of a database table including columns,
|
|
118
|
+
* indexes, and constraints.
|
|
119
|
+
*
|
|
120
|
+
* @public
|
|
121
|
+
*/
|
|
122
|
+
interface TableDefinition {
|
|
123
|
+
/** Table name */
|
|
124
|
+
name: string;
|
|
125
|
+
/** Column definitions */
|
|
126
|
+
columns: ColumnDefinition[];
|
|
127
|
+
/** Composite primary key (if not defined at column level) */
|
|
128
|
+
primaryKey?: string[];
|
|
129
|
+
/** Index definitions */
|
|
130
|
+
indexes?: IndexDefinition[];
|
|
131
|
+
/** Table-level constraints */
|
|
132
|
+
constraints?: TableConstraint[];
|
|
133
|
+
/** Table comment/description */
|
|
134
|
+
comment?: string;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Options for table creation.
|
|
138
|
+
*
|
|
139
|
+
* @public
|
|
140
|
+
*/
|
|
141
|
+
interface CreateTableOptions {
|
|
142
|
+
/** Don't throw error if table exists */
|
|
143
|
+
ifNotExists?: boolean;
|
|
144
|
+
/** Temporary table (session-scoped) */
|
|
145
|
+
temporary?: boolean;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Options for table dropping.
|
|
149
|
+
*
|
|
150
|
+
* @public
|
|
151
|
+
*/
|
|
152
|
+
interface DropTableOptions {
|
|
153
|
+
/** Don't throw error if table doesn't exist */
|
|
154
|
+
ifExists?: boolean;
|
|
155
|
+
/** Drop dependent objects (CASCADE) */
|
|
156
|
+
cascade?: boolean;
|
|
157
|
+
/** Restrict drop if dependencies exist (default) */
|
|
158
|
+
restrict?: boolean;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Options for table alteration.
|
|
162
|
+
*
|
|
163
|
+
* @public
|
|
164
|
+
*/
|
|
165
|
+
interface AlterTableOptions {
|
|
166
|
+
/** Validation mode for constraints */
|
|
167
|
+
validate?: boolean;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Table alteration operations.
|
|
171
|
+
*
|
|
172
|
+
* @remarks
|
|
173
|
+
* Defines the types of operations that can be performed when altering a table.
|
|
174
|
+
*
|
|
175
|
+
* @public
|
|
176
|
+
*/
|
|
177
|
+
type AlterTableOperation = {
|
|
178
|
+
kind: "add_column";
|
|
179
|
+
column: ColumnDefinition;
|
|
180
|
+
} | {
|
|
181
|
+
kind: "drop_column";
|
|
182
|
+
columnName: string;
|
|
183
|
+
cascade?: boolean;
|
|
184
|
+
} | {
|
|
185
|
+
kind: "rename_column";
|
|
186
|
+
from: string;
|
|
187
|
+
to: string;
|
|
188
|
+
} | {
|
|
189
|
+
kind: "modify_column";
|
|
190
|
+
column: ColumnDefinition;
|
|
191
|
+
} | {
|
|
192
|
+
kind: "add_constraint";
|
|
193
|
+
constraint: TableConstraint;
|
|
194
|
+
} | {
|
|
195
|
+
kind: "drop_constraint";
|
|
196
|
+
constraintName: string;
|
|
197
|
+
cascade?: boolean;
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
export type { AlterTableOperation as A, CreateTableOptions as C, DropTableOptions as D, IndexDefinition as I, TableDefinition as T, AlterTableOptions as a, ColumnDefinition as b, TableConstraint as c };
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { a as SqlParam } from './core-CVO7WYDj.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Database schema type definitions.
|
|
5
|
+
*
|
|
6
|
+
* @packageDocumentation
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Column definition for schema operations.
|
|
11
|
+
*
|
|
12
|
+
* @remarks
|
|
13
|
+
* Defines the structure of a database column in a database-agnostic way.
|
|
14
|
+
* Adapters translate these definitions to dialect-specific DDL.
|
|
15
|
+
*
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
interface ColumnDefinition {
|
|
19
|
+
/** Column name */
|
|
20
|
+
name: string;
|
|
21
|
+
/**
|
|
22
|
+
* Column data type.
|
|
23
|
+
*
|
|
24
|
+
* @remarks
|
|
25
|
+
* Common types across databases:
|
|
26
|
+
* - Text: varchar(n), text, char(n)
|
|
27
|
+
* - Numbers: int, bigint, decimal, numeric
|
|
28
|
+
* - Boolean: boolean
|
|
29
|
+
* - Date/Time: timestamp, date, time
|
|
30
|
+
* - JSON: json, jsonb (PostgreSQL)
|
|
31
|
+
* - UUID: uuid (PostgreSQL), char(36) (MySQL/SQLite)
|
|
32
|
+
*
|
|
33
|
+
* Adapters handle dialect-specific type mapping.
|
|
34
|
+
*/
|
|
35
|
+
type: string;
|
|
36
|
+
/** Allow NULL values (default: true) */
|
|
37
|
+
nullable?: boolean;
|
|
38
|
+
/** Primary key column */
|
|
39
|
+
primaryKey?: boolean;
|
|
40
|
+
/** Unique constraint */
|
|
41
|
+
unique?: boolean;
|
|
42
|
+
/** Default value (literal or SQL expression) */
|
|
43
|
+
default?: SqlParam | {
|
|
44
|
+
sql: string;
|
|
45
|
+
};
|
|
46
|
+
/** Foreign key reference */
|
|
47
|
+
references?: {
|
|
48
|
+
/** Referenced table name */
|
|
49
|
+
table: string;
|
|
50
|
+
/** Referenced column name */
|
|
51
|
+
column: string;
|
|
52
|
+
/** Action on DELETE */
|
|
53
|
+
onDelete?: "no action" | "restrict" | "cascade" | "set null" | "set default";
|
|
54
|
+
/** Action on UPDATE */
|
|
55
|
+
onUpdate?: "no action" | "restrict" | "cascade" | "set null" | "set default";
|
|
56
|
+
};
|
|
57
|
+
/** Check constraint expression */
|
|
58
|
+
check?: string;
|
|
59
|
+
/** Generated column definition (computed column) */
|
|
60
|
+
generated?: {
|
|
61
|
+
/** SQL expression to generate the value */
|
|
62
|
+
as: string;
|
|
63
|
+
/** Store the value (true) or compute on-the-fly (false) */
|
|
64
|
+
stored?: boolean;
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Index definition for schema operations.
|
|
69
|
+
*
|
|
70
|
+
* @remarks
|
|
71
|
+
* Defines database indexes for performance optimization.
|
|
72
|
+
*
|
|
73
|
+
* @public
|
|
74
|
+
*/
|
|
75
|
+
interface IndexDefinition {
|
|
76
|
+
/** Index name */
|
|
77
|
+
name: string;
|
|
78
|
+
/** Columns included in the index */
|
|
79
|
+
columns: string[];
|
|
80
|
+
/** Unique index (enforces uniqueness) */
|
|
81
|
+
unique?: boolean;
|
|
82
|
+
/** Partial index condition (WHERE clause) */
|
|
83
|
+
where?: string;
|
|
84
|
+
/** Index type (database-specific) */
|
|
85
|
+
using?: "btree" | "hash" | "gin" | "gist" | "brin";
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Table constraint definition.
|
|
89
|
+
*
|
|
90
|
+
* @public
|
|
91
|
+
*/
|
|
92
|
+
interface TableConstraint {
|
|
93
|
+
/** Constraint name */
|
|
94
|
+
name: string;
|
|
95
|
+
/** Constraint type */
|
|
96
|
+
type: "unique" | "check" | "foreign_key" | "primary_key";
|
|
97
|
+
/** Columns involved in the constraint */
|
|
98
|
+
columns?: string[];
|
|
99
|
+
/** Check constraint expression */
|
|
100
|
+
expression?: string;
|
|
101
|
+
/** Foreign key reference (for foreign_key type) */
|
|
102
|
+
references?: {
|
|
103
|
+
/** Referenced table name */
|
|
104
|
+
table: string;
|
|
105
|
+
/** Referenced columns */
|
|
106
|
+
columns: string[];
|
|
107
|
+
/** Action on DELETE */
|
|
108
|
+
onDelete?: "no action" | "restrict" | "cascade" | "set null" | "set default";
|
|
109
|
+
/** Action on UPDATE */
|
|
110
|
+
onUpdate?: "no action" | "restrict" | "cascade" | "set null" | "set default";
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Complete table definition.
|
|
115
|
+
*
|
|
116
|
+
* @remarks
|
|
117
|
+
* Defines the complete structure of a database table including columns,
|
|
118
|
+
* indexes, and constraints.
|
|
119
|
+
*
|
|
120
|
+
* @public
|
|
121
|
+
*/
|
|
122
|
+
interface TableDefinition {
|
|
123
|
+
/** Table name */
|
|
124
|
+
name: string;
|
|
125
|
+
/** Column definitions */
|
|
126
|
+
columns: ColumnDefinition[];
|
|
127
|
+
/** Composite primary key (if not defined at column level) */
|
|
128
|
+
primaryKey?: string[];
|
|
129
|
+
/** Index definitions */
|
|
130
|
+
indexes?: IndexDefinition[];
|
|
131
|
+
/** Table-level constraints */
|
|
132
|
+
constraints?: TableConstraint[];
|
|
133
|
+
/** Table comment/description */
|
|
134
|
+
comment?: string;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Options for table creation.
|
|
138
|
+
*
|
|
139
|
+
* @public
|
|
140
|
+
*/
|
|
141
|
+
interface CreateTableOptions {
|
|
142
|
+
/** Don't throw error if table exists */
|
|
143
|
+
ifNotExists?: boolean;
|
|
144
|
+
/** Temporary table (session-scoped) */
|
|
145
|
+
temporary?: boolean;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Options for table dropping.
|
|
149
|
+
*
|
|
150
|
+
* @public
|
|
151
|
+
*/
|
|
152
|
+
interface DropTableOptions {
|
|
153
|
+
/** Don't throw error if table doesn't exist */
|
|
154
|
+
ifExists?: boolean;
|
|
155
|
+
/** Drop dependent objects (CASCADE) */
|
|
156
|
+
cascade?: boolean;
|
|
157
|
+
/** Restrict drop if dependencies exist (default) */
|
|
158
|
+
restrict?: boolean;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Options for table alteration.
|
|
162
|
+
*
|
|
163
|
+
* @public
|
|
164
|
+
*/
|
|
165
|
+
interface AlterTableOptions {
|
|
166
|
+
/** Validation mode for constraints */
|
|
167
|
+
validate?: boolean;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Table alteration operations.
|
|
171
|
+
*
|
|
172
|
+
* @remarks
|
|
173
|
+
* Defines the types of operations that can be performed when altering a table.
|
|
174
|
+
*
|
|
175
|
+
* @public
|
|
176
|
+
*/
|
|
177
|
+
type AlterTableOperation = {
|
|
178
|
+
kind: "add_column";
|
|
179
|
+
column: ColumnDefinition;
|
|
180
|
+
} | {
|
|
181
|
+
kind: "drop_column";
|
|
182
|
+
columnName: string;
|
|
183
|
+
cascade?: boolean;
|
|
184
|
+
} | {
|
|
185
|
+
kind: "rename_column";
|
|
186
|
+
from: string;
|
|
187
|
+
to: string;
|
|
188
|
+
} | {
|
|
189
|
+
kind: "modify_column";
|
|
190
|
+
column: ColumnDefinition;
|
|
191
|
+
} | {
|
|
192
|
+
kind: "add_constraint";
|
|
193
|
+
constraint: TableConstraint;
|
|
194
|
+
} | {
|
|
195
|
+
kind: "drop_constraint";
|
|
196
|
+
constraintName: string;
|
|
197
|
+
cascade?: boolean;
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
export type { AlterTableOperation as A, CreateTableOptions as C, DropTableOptions as D, IndexDefinition as I, TableDefinition as T, AlterTableOptions as a, ColumnDefinition as b, TableConstraint as c };
|