@drizzle-adapter/d1 1.0.15 → 1.0.18

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.
Files changed (41) hide show
  1. package/.wrangler/tmp/bundle-CHc9gh/checked-fetch.js +30 -0
  2. package/.wrangler/tmp/bundle-CHc9gh/middleware-insertion-facade.js +11 -0
  3. package/.wrangler/tmp/bundle-CHc9gh/middleware-loader.entry.ts +134 -0
  4. package/.wrangler/tmp/bundle-CHc9gh/strip-cf-connecting-ip-header.js +13 -0
  5. package/.wrangler/tmp/bundle-kh10f5/checked-fetch.js +30 -0
  6. package/.wrangler/tmp/bundle-kh10f5/middleware-insertion-facade.js +11 -0
  7. package/.wrangler/tmp/bundle-kh10f5/middleware-loader.entry.ts +134 -0
  8. package/.wrangler/tmp/bundle-kh10f5/strip-cf-connecting-ip-header.js +13 -0
  9. package/.wrangler/tmp/dev-BRrYv0/worker.js +6512 -0
  10. package/.wrangler/tmp/dev-BRrYv0/worker.js.map +8 -0
  11. package/.wrangler/tmp/dev-NlAyrN/worker.js +6512 -0
  12. package/.wrangler/tmp/dev-NlAyrN/worker.js.map +8 -0
  13. package/LICENSE +21 -674
  14. package/README.md +41 -0
  15. package/dist/Adapter/D1DrizzleAdapter.d.ts +13 -9
  16. package/dist/Adapter/D1DrizzleAdapter.js +14 -10
  17. package/dist/Adapter/D1DrizzleConnection.d.ts +6 -2
  18. package/dist/Adapter/D1DrizzleConnection.js +14 -2
  19. package/dist/Adapter/D1DrizzleDataTypes.d.ts +4 -0
  20. package/dist/Adapter/D1DrizzleDataTypes.js +4 -0
  21. package/dist/Adapter/D1DrizzleMigrator.d.ts +5 -1
  22. package/dist/Adapter/D1DrizzleMigrator.js +5 -1
  23. package/dist/Factory/D1DrizzleAdapterFactory.d.ts +8 -4
  24. package/dist/Factory/D1DrizzleAdapterFactory.js +6 -2
  25. package/dist/Factory/D1DrizzleDataTypesFactory.d.ts +5 -1
  26. package/dist/Factory/D1DrizzleDataTypesFactory.js +5 -1
  27. package/dist/Factory/D1DrizzleMigratorFactory.d.ts +6 -2
  28. package/dist/Factory/D1DrizzleMigratorFactory.js +6 -2
  29. package/dist/Interface/D1DrizzleClientInterface.d.ts +5 -1
  30. package/dist/Type/Types.d.ts +4 -0
  31. package/eslint.config.mjs +1 -1
  32. package/package.json +11 -10
  33. package/src/Adapter/D1DrizzleAdapter.ts +16 -11
  34. package/src/Adapter/D1DrizzleConnection.ts +18 -3
  35. package/src/Adapter/D1DrizzleDataTypes.ts +4 -0
  36. package/src/Adapter/D1DrizzleMigrator.ts +6 -1
  37. package/src/Factory/D1DrizzleAdapterFactory.ts +9 -4
  38. package/src/Factory/D1DrizzleDataTypesFactory.ts +5 -1
  39. package/src/Factory/D1DrizzleMigratorFactory.ts +7 -2
  40. package/src/Interface/D1DrizzleClientInterface.ts +5 -1
  41. package/src/Type/Types.ts +4 -0
package/README.md CHANGED
@@ -46,6 +46,47 @@ import '@drizzle-adapter/d1';
46
46
  import { DrizzleAdapterFactory } from '@drizzle-adapter/core';
47
47
  ```
48
48
 
49
+ ## D1 Compatibility Layer
50
+
51
+ This adapter provides several compatibility enhancements to make D1 work seamlessly with existing Drizzle ORM code:
52
+
53
+ ### Execute Method Mapping
54
+ D1's Drizzle implementation uses `run()` instead of the standard `execute()` method. This adapter automatically maps `execute()` to `run()` for compatibility:
55
+
56
+ ```typescript
57
+ // Both of these work identically
58
+ await client.execute(sql`SELECT * FROM users`);
59
+ await client.run(sql`SELECT * FROM users`);
60
+ ```
61
+
62
+ ### Transaction Compatibility
63
+ **Important**: Cloudflare D1 does not support real SQL transactions. This adapter provides a compatibility layer that allows transaction-based code to run without modifications, but **without transaction guarantees**:
64
+
65
+ ```typescript
66
+ // This code will run without errors, but operations are NOT atomic
67
+ await client.transaction(async (tx) => {
68
+ await tx.insert(users).values({ name: 'John' });
69
+ await tx.update(posts).set({ published: 1 });
70
+ // If an error occurs here, previous operations will NOT be rolled back
71
+ });
72
+ ```
73
+
74
+ **For atomic operations**, use D1's batch API directly:
75
+
76
+ ```typescript
77
+ // This provides atomic execution - all succeed or all fail
78
+ const results = await client.batch([
79
+ client.insert(users).values({ name: 'John' }).prepare(),
80
+ client.update(posts).set({ published: 1 }).prepare()
81
+ ]);
82
+ ```
83
+
84
+ ### Migration Considerations
85
+ - **Transaction Compatibility**: Existing code using `db.transaction()` will work without modification
86
+ - **No Rollback**: Failed operations cannot be automatically rolled back
87
+ - **Batch Operations**: Use `db.batch()` for operations that require atomicity
88
+ - **Error Handling**: Implement manual cleanup logic for critical operations
89
+
49
90
  ## Usage
50
91
 
51
92
  ### Cloudflare Workers Setup
@@ -1,31 +1,35 @@
1
1
  import type { D1Database } from '@cloudflare/workers-types';
2
+ import type { DrizzleAdapterInterface } from '@drizzle-adapter/core';
2
3
  import { D1DrizzleConnection } from './D1DrizzleConnection.js';
3
4
  import { D1DrizzleDataTypes } from './D1DrizzleDataTypes.js';
4
- import type { DrizzleAdapterInterface } from '@drizzle-adapter/core';
5
+ /**
6
+ * D1 adapter implementation for Drizzle ORM.
7
+ * Provides D1-specific database operations and connection management.
8
+ */
5
9
  export declare class D1DrizzleAdapter implements DrizzleAdapterInterface {
6
10
  private connection;
7
11
  /**
8
12
  * Constructor.
9
13
  *
10
- * @param {D1Database} driver
14
+ * @param {D1Database} driver - The D1 database driver instance
11
15
  */
12
16
  constructor(driver: D1Database);
13
17
  /**
14
- * Returns the dialect.
18
+ * Returns the connection.
15
19
  *
16
- * @returns {string}
20
+ * @returns {Promise<D1DrizzleConnection>} A promise that resolves to the D1 connection instance
17
21
  */
18
- getDialect(): string;
22
+ getConnection(): Promise<D1DrizzleConnection>;
19
23
  /**
20
24
  * Returns the data types.
21
25
  *
22
- * @returns {D1DrizzleDataTypes}
26
+ * @returns {D1DrizzleDataTypes} The D1 data types instance
23
27
  */
24
28
  getDataTypes(): D1DrizzleDataTypes;
25
29
  /**
26
- * Returns the connection.
30
+ * Returns the dialect.
27
31
  *
28
- * @returns {Promise<D1DrizzleConnection>}
32
+ * @returns {string} The database dialect string
29
33
  */
30
- getConnection(): Promise<D1DrizzleConnection>;
34
+ getDialect(): string;
31
35
  }
@@ -1,37 +1,41 @@
1
1
  import { D1DrizzleConnection } from './D1DrizzleConnection.js';
2
2
  import { D1DrizzleDataTypes } from './D1DrizzleDataTypes.js';
3
+ /**
4
+ * D1 adapter implementation for Drizzle ORM.
5
+ * Provides D1-specific database operations and connection management.
6
+ */
3
7
  export class D1DrizzleAdapter {
4
8
  connection;
5
9
  /**
6
10
  * Constructor.
7
11
  *
8
- * @param {D1Database} driver
12
+ * @param {D1Database} driver - The D1 database driver instance
9
13
  */
10
14
  constructor(driver) {
11
15
  this.connection = new D1DrizzleConnection(driver);
12
16
  }
13
17
  /**
14
- * Returns the dialect.
18
+ * Returns the connection.
15
19
  *
16
- * @returns {string}
20
+ * @returns {Promise<D1DrizzleConnection>} A promise that resolves to the D1 connection instance
17
21
  */
18
- getDialect() {
19
- return 'sqlite';
22
+ async getConnection() {
23
+ return this.connection.connect();
20
24
  }
21
25
  /**
22
26
  * Returns the data types.
23
27
  *
24
- * @returns {D1DrizzleDataTypes}
28
+ * @returns {D1DrizzleDataTypes} The D1 data types instance
25
29
  */
26
30
  getDataTypes() {
27
31
  return new D1DrizzleDataTypes();
28
32
  }
29
33
  /**
30
- * Returns the connection.
34
+ * Returns the dialect.
31
35
  *
32
- * @returns {Promise<D1DrizzleConnection>}
36
+ * @returns {string} The database dialect string
33
37
  */
34
- async getConnection() {
35
- return this.connection.connect();
38
+ getDialect() {
39
+ return 'sqlite';
36
40
  }
37
41
  }
@@ -1,12 +1,16 @@
1
1
  import type { D1Database } from '@cloudflare/workers-types';
2
2
  import type { DrizzleConnectionInterface } from '@drizzle-adapter/core';
3
3
  import type { D1DrizzleClientInterface } from 'src/Interface';
4
+ /**
5
+ * D1 connection implementation for Drizzle ORM.
6
+ * Manages database connections and provides client access for D1 databases.
7
+ */
4
8
  export declare class D1DrizzleConnection implements DrizzleConnectionInterface {
5
9
  private client;
6
10
  /**
7
11
  * Constructor.
8
12
  *
9
- * @param {D1Database} driver
13
+ * @param {D1Database} driver - The D1 database driver instance
10
14
  */
11
15
  constructor(driver: D1Database);
12
16
  /**
@@ -24,7 +28,7 @@ export declare class D1DrizzleConnection implements DrizzleConnectionInterface {
24
28
  /**
25
29
  * Returns the client.
26
30
  *
27
- * @returns {D1DrizzleClientInterface}
31
+ * @returns {D1DrizzleClientInterface} The D1 Drizzle client instance
28
32
  */
29
33
  getClient(): D1DrizzleClientInterface;
30
34
  }
@@ -1,15 +1,27 @@
1
1
  import { drizzle } from 'drizzle-orm/d1';
2
+ /**
3
+ * D1 connection implementation for Drizzle ORM.
4
+ * Manages database connections and provides client access for D1 databases.
5
+ */
2
6
  export class D1DrizzleConnection {
3
7
  client;
4
8
  /**
5
9
  * Constructor.
6
10
  *
7
- * @param {D1Database} driver
11
+ * @param {D1Database} driver - The D1 database driver instance
8
12
  */
9
13
  constructor(driver) {
10
14
  // We want to add the execute method as an alias for run
11
15
  const database = drizzle(driver);
12
16
  database.execute = database.run;
17
+ // Override transaction method to provide transaction-like behavior
18
+ // Since D1 doesn't support real transactions, we pass the original client
19
+ // Users can implement their own batching if needed for atomicity
20
+ database.transaction = async (callback) => {
21
+ // For now, just pass the original client - no transaction isolation
22
+ // This allows code to work without modifications while being explicit about the limitation
23
+ return await callback(database);
24
+ };
13
25
  this.client = database;
14
26
  }
15
27
  /**
@@ -33,7 +45,7 @@ export class D1DrizzleConnection {
33
45
  /**
34
46
  * Returns the client.
35
47
  *
36
- * @returns {D1DrizzleClientInterface}
48
+ * @returns {D1DrizzleClientInterface} The D1 Drizzle client instance
37
49
  */
38
50
  getClient() {
39
51
  return this.client;
@@ -1,3 +1,7 @@
1
1
  import { SqliteCoreDrizzleDataTypes } from '@drizzle-adapter/sqlite-core';
2
+ /**
3
+ * D1 data types implementation for Drizzle ORM.
4
+ * Extends the core SQLite data types with D1-specific functionality.
5
+ */
2
6
  export declare class D1DrizzleDataTypes extends SqliteCoreDrizzleDataTypes {
3
7
  }
@@ -1,3 +1,7 @@
1
1
  import { SqliteCoreDrizzleDataTypes } from '@drizzle-adapter/sqlite-core';
2
+ /**
3
+ * D1 data types implementation for Drizzle ORM.
4
+ * Extends the core SQLite data types with D1-specific functionality.
5
+ */
2
6
  export class D1DrizzleDataTypes extends SqliteCoreDrizzleDataTypes {
3
7
  }
@@ -1,5 +1,9 @@
1
1
  import type { DrizzleMigratorInterface, TypeDrizzleMigratorConfig } from '@drizzle-adapter/core';
2
2
  import type { D1DrizzleClientInterface } from '../Interface/index.js';
3
+ /**
4
+ * D1 migrator implementation for Drizzle ORM.
5
+ * Handles database migrations for D1 databases.
6
+ */
3
7
  export declare class D1DrizzleMigrator implements DrizzleMigratorInterface {
4
8
  private readonly config;
5
9
  /**
@@ -11,7 +15,7 @@ export declare class D1DrizzleMigrator implements DrizzleMigratorInterface {
11
15
  /**
12
16
  * Migrate the database.
13
17
  *
14
- * @param {DrizzleClientInterface} client The Drizzle client.
18
+ * @param {D1DrizzleClientInterface} client The Drizzle client.
15
19
  */
16
20
  migrate(client: D1DrizzleClientInterface): Promise<void>;
17
21
  }
@@ -1,4 +1,8 @@
1
1
  import { DrizzleD1Database } from 'drizzle-orm/d1/driver';
2
+ /**
3
+ * D1 migrator implementation for Drizzle ORM.
4
+ * Handles database migrations for D1 databases.
5
+ */
2
6
  export class D1DrizzleMigrator {
3
7
  config;
4
8
  /**
@@ -12,7 +16,7 @@ export class D1DrizzleMigrator {
12
16
  /**
13
17
  * Migrate the database.
14
18
  *
15
- * @param {DrizzleClientInterface} client The Drizzle client.
19
+ * @param {D1DrizzleClientInterface} client The Drizzle client.
16
20
  */
17
21
  async migrate(client) {
18
22
  const { migrate } = await import('drizzle-orm/d1/migrator');
@@ -1,12 +1,16 @@
1
- import type { TypeD1DatabaseConfig } from '../Type/Types.js';
2
- import { D1DrizzleAdapter } from '../Adapter/D1DrizzleAdapter.js';
3
1
  import type { DrizzleAdapterFactoryInterface } from '@drizzle-adapter/core';
2
+ import { D1DrizzleAdapter } from '../Adapter/D1DrizzleAdapter.js';
3
+ import type { TypeD1DatabaseConfig } from '../Type/Types.js';
4
+ /**
5
+ * Factory for creating D1 adapter instances.
6
+ * Implements the DrizzleAdapterFactoryInterface for D1 database operations.
7
+ */
4
8
  export declare class D1DrizzleAdapterFactory implements DrizzleAdapterFactoryInterface {
5
9
  /**
6
10
  * Returns a adapter.
7
11
  *
8
- * @param {TypeD1DatabaseConfig} databaseConfig
9
- * @returns {D1DrizzleAdapter}
12
+ * @param {TypeD1DatabaseConfig} databaseConfig - The D1 database configuration
13
+ * @returns {D1DrizzleAdapter} A new D1 adapter instance
10
14
  */
11
15
  create(databaseConfig: TypeD1DatabaseConfig): D1DrizzleAdapter;
12
16
  }
@@ -1,10 +1,14 @@
1
1
  import { D1DrizzleAdapter } from '../Adapter/D1DrizzleAdapter.js';
2
+ /**
3
+ * Factory for creating D1 adapter instances.
4
+ * Implements the DrizzleAdapterFactoryInterface for D1 database operations.
5
+ */
2
6
  export class D1DrizzleAdapterFactory {
3
7
  /**
4
8
  * Returns a adapter.
5
9
  *
6
- * @param {TypeD1DatabaseConfig} databaseConfig
7
- * @returns {D1DrizzleAdapter}
10
+ * @param {TypeD1DatabaseConfig} databaseConfig - The D1 database configuration
11
+ * @returns {D1DrizzleAdapter} A new D1 adapter instance
8
12
  */
9
13
  create(databaseConfig) {
10
14
  return new D1DrizzleAdapter(databaseConfig.DATABASE);
@@ -1,11 +1,15 @@
1
1
  import type { DrizzleDataTypesFactoryInterface, TypeDrizzleDatabaseConfig } from '@drizzle-adapter/core';
2
2
  import { SqliteCoreDrizzleDataTypes } from '@drizzle-adapter/sqlite-core';
3
+ /**
4
+ * Factory for creating D1 data types instances.
5
+ * Implements the DrizzleDataTypesFactoryInterface for D1 database operations.
6
+ */
3
7
  export declare class D1DrizzleDataTypesFactory implements DrizzleDataTypesFactoryInterface {
4
8
  /**
5
9
  * Creates a new data types instance.
6
10
  *
7
11
  * @param {TypeDrizzleDatabaseConfig} _config - Not used in this implementation
8
- * @returns {SqliteCoreDrizzleDataTypes}
12
+ * @returns {SqliteCoreDrizzleDataTypes} A new SQLite core data types instance
9
13
  */
10
14
  create(_config: TypeDrizzleDatabaseConfig): SqliteCoreDrizzleDataTypes;
11
15
  }
@@ -1,10 +1,14 @@
1
1
  import { SqliteCoreDrizzleDataTypes } from '@drizzle-adapter/sqlite-core';
2
+ /**
3
+ * Factory for creating D1 data types instances.
4
+ * Implements the DrizzleDataTypesFactoryInterface for D1 database operations.
5
+ */
2
6
  export class D1DrizzleDataTypesFactory {
3
7
  /**
4
8
  * Creates a new data types instance.
5
9
  *
6
10
  * @param {TypeDrizzleDatabaseConfig} _config - Not used in this implementation
7
- * @returns {SqliteCoreDrizzleDataTypes}
11
+ * @returns {SqliteCoreDrizzleDataTypes} A new SQLite core data types instance
8
12
  */
9
13
  create(_config) {
10
14
  return new SqliteCoreDrizzleDataTypes();
@@ -1,11 +1,15 @@
1
1
  import type { DrizzleMigratorFactoryInterface, TypeDrizzleMigratorConfig } from '@drizzle-adapter/core';
2
2
  import { D1DrizzleMigrator } from '../migrator.js';
3
+ /**
4
+ * Factory for creating D1 migrator instances.
5
+ * Implements the DrizzleMigratorFactoryInterface for D1 database migrations.
6
+ */
3
7
  export declare class D1DrizzleMigratorFactory implements DrizzleMigratorFactoryInterface {
4
8
  /**
5
9
  * Returns a new migrator.
6
10
  *
7
- * @param {TypeDrizzleMigratorConfig} config
8
- * @returns {D1DrizzleMigrator}
11
+ * @param {TypeDrizzleMigratorConfig} config - The migrator configuration
12
+ * @returns {D1DrizzleMigrator} A new D1 migrator instance
9
13
  */
10
14
  create(config: TypeDrizzleMigratorConfig): D1DrizzleMigrator;
11
15
  }
@@ -1,10 +1,14 @@
1
1
  import { D1DrizzleMigrator } from '../migrator.js';
2
+ /**
3
+ * Factory for creating D1 migrator instances.
4
+ * Implements the DrizzleMigratorFactoryInterface for D1 database migrations.
5
+ */
2
6
  export class D1DrizzleMigratorFactory {
3
7
  /**
4
8
  * Returns a new migrator.
5
9
  *
6
- * @param {TypeDrizzleMigratorConfig} config
7
- * @returns {D1DrizzleMigrator}
10
+ * @param {TypeDrizzleMigratorConfig} config - The migrator configuration
11
+ * @returns {D1DrizzleMigrator} A new D1 migrator instance
8
12
  */
9
13
  create(config) {
10
14
  return new D1DrizzleMigrator(config);
@@ -1,5 +1,9 @@
1
- import type { AnyD1Database } from 'drizzle-orm/d1';
2
1
  import type { DrizzleClientInterface } from '@drizzle-adapter/core';
2
+ import type { AnyD1Database } from 'drizzle-orm/d1';
3
+ /**
4
+ * Interface for D1 Drizzle client operations.
5
+ * Extends the core DrizzleClientInterface with D1-specific database operations.
6
+ */
3
7
  export interface D1DrizzleClientInterface extends DrizzleClientInterface {
4
8
  execute(...args: any[]): ReturnType<AnyD1Database['run']>;
5
9
  $with(...args: any[]): ReturnType<AnyD1Database['$with']>;
@@ -1,5 +1,9 @@
1
1
  import type { D1Database } from '@cloudflare/workers-types';
2
2
  import type { TypeDrizzleDatabaseConfig } from '@drizzle-adapter/core';
3
+ /**
4
+ * Configuration interface for D1 database connections.
5
+ * Extends the core database configuration with D1-specific settings.
6
+ */
3
7
  export interface TypeD1DatabaseConfig extends TypeDrizzleDatabaseConfig {
4
8
  readonly DATABASE: D1Database;
5
9
  }
package/eslint.config.mjs CHANGED
@@ -3,4 +3,4 @@ import eslintConfig from '@dmitryrechkin/eslint-standard/eslint.config.mjs';
3
3
  export default eslintConfig({
4
4
  tsconfigPath: './tsconfig.eslint.json',
5
5
  ignores: ['packages/**', 'tests/**'],
6
- });
6
+ });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@drizzle-adapter/d1",
3
3
  "type": "module",
4
- "version": "1.0.15",
4
+ "version": "1.0.18",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "exports": {
@@ -17,21 +17,22 @@
17
17
  "devDependencies": {
18
18
  "@cloudflare/workers-types": "^4.20250419.0",
19
19
  "@dmitryrechkin/eslint-standard": "^1.0.7",
20
- "dotenv": "^16.5.0",
21
- "eslint": "^8.57.1",
22
- "eslint-plugin-unused-imports": "^3.2.0",
23
- "shx": "^0.3.4",
20
+ "dotenv": "^17.0.1",
21
+ "eslint": "^9.30.1",
22
+ "eslint-plugin-unused-imports": "^4.1.4",
23
+ "shx": "^0.4.0",
24
24
  "tsc-esm-fix": "^3.1.2",
25
25
  "tsconfig-paths": "^4.2.0",
26
26
  "typescript": "^5.8.3",
27
- "vitest": "^0.24.5",
28
- "wrangler": "^3.114.6"
27
+ "vitest": "^3.2.4",
28
+ "wrangler": "^3.114.11"
29
29
  },
30
30
  "dependencies": {
31
- "drizzle-orm": "^0.36.4",
32
- "@drizzle-adapter/core": "^1.0.12",
33
- "@drizzle-adapter/sqlite-core": "^1.0.12"
31
+ "drizzle-orm": "^0.44.2",
32
+ "@drizzle-adapter/core": "^1.0.14",
33
+ "@drizzle-adapter/sqlite-core": "^1.0.14"
34
34
  },
35
+ "license": "MIT",
35
36
  "scripts": {
36
37
  "lint": "eslint src/",
37
38
  "format": "eslint --fix src/",
@@ -1,8 +1,13 @@
1
1
  import type { D1Database } from '@cloudflare/workers-types';
2
+ import type { DrizzleAdapterInterface } from '@drizzle-adapter/core';
3
+
2
4
  import { D1DrizzleConnection } from './D1DrizzleConnection';
3
5
  import { D1DrizzleDataTypes } from './D1DrizzleDataTypes';
4
- import type { DrizzleAdapterInterface } from '@drizzle-adapter/core';
5
6
 
7
+ /**
8
+ * D1 adapter implementation for Drizzle ORM.
9
+ * Provides D1-specific database operations and connection management.
10
+ */
6
11
  export class D1DrizzleAdapter implements DrizzleAdapterInterface
7
12
  {
8
13
  private connection: D1DrizzleConnection;
@@ -10,7 +15,7 @@ export class D1DrizzleAdapter implements DrizzleAdapterInterface
10
15
  /**
11
16
  * Constructor.
12
17
  *
13
- * @param {D1Database} driver
18
+ * @param {D1Database} driver - The D1 database driver instance
14
19
  */
15
20
  public constructor(driver: D1Database)
16
21
  {
@@ -18,19 +23,19 @@ export class D1DrizzleAdapter implements DrizzleAdapterInterface
18
23
  }
19
24
 
20
25
  /**
21
- * Returns the dialect.
26
+ * Returns the connection.
22
27
  *
23
- * @returns {string}
28
+ * @returns {Promise<D1DrizzleConnection>} A promise that resolves to the D1 connection instance
24
29
  */
25
- public getDialect(): string
30
+ public async getConnection(): Promise<D1DrizzleConnection>
26
31
  {
27
- return 'sqlite';
32
+ return this.connection.connect();
28
33
  }
29
34
 
30
35
  /**
31
36
  * Returns the data types.
32
37
  *
33
- * @returns {D1DrizzleDataTypes}
38
+ * @returns {D1DrizzleDataTypes} The D1 data types instance
34
39
  */
35
40
  public getDataTypes(): D1DrizzleDataTypes
36
41
  {
@@ -38,12 +43,12 @@ export class D1DrizzleAdapter implements DrizzleAdapterInterface
38
43
  }
39
44
 
40
45
  /**
41
- * Returns the connection.
46
+ * Returns the dialect.
42
47
  *
43
- * @returns {Promise<D1DrizzleConnection>}
48
+ * @returns {string} The database dialect string
44
49
  */
45
- public async getConnection(): Promise<D1DrizzleConnection>
50
+ public getDialect(): string
46
51
  {
47
- return this.connection.connect();
52
+ return 'sqlite';
48
53
  }
49
54
  }
@@ -1,8 +1,12 @@
1
1
  import type { D1Database } from '@cloudflare/workers-types';
2
- import { drizzle } from 'drizzle-orm/d1';
3
2
  import type { DrizzleConnectionInterface } from '@drizzle-adapter/core';
3
+ import { drizzle } from 'drizzle-orm/d1';
4
4
  import type { D1DrizzleClientInterface } from 'src/Interface';
5
5
 
6
+ /**
7
+ * D1 connection implementation for Drizzle ORM.
8
+ * Manages database connections and provides client access for D1 databases.
9
+ */
6
10
  export class D1DrizzleConnection implements DrizzleConnectionInterface
7
11
  {
8
12
  private client: D1DrizzleClientInterface;
@@ -10,7 +14,7 @@ export class D1DrizzleConnection implements DrizzleConnectionInterface
10
14
  /**
11
15
  * Constructor.
12
16
  *
13
- * @param {D1Database} driver
17
+ * @param {D1Database} driver - The D1 database driver instance
14
18
  */
15
19
  public constructor(driver: D1Database)
16
20
  {
@@ -18,6 +22,17 @@ export class D1DrizzleConnection implements DrizzleConnectionInterface
18
22
  const database: ReturnType<typeof drizzle> | D1DrizzleClientInterface = drizzle(driver);
19
23
  (database as unknown as D1DrizzleClientInterface).execute = database.run;
20
24
 
25
+ // Override transaction method to provide transaction-like behavior
26
+ // Since D1 doesn't support real transactions, we pass the original client
27
+ // Users can implement their own batching if needed for atomicity
28
+ (database as unknown as D1DrizzleClientInterface).transaction = async <T>(
29
+ callback: (tx: D1DrizzleClientInterface) => Promise<T>
30
+ ): Promise<T> => {
31
+ // For now, just pass the original client - no transaction isolation
32
+ // This allows code to work without modifications while being explicit about the limitation
33
+ return await callback(database as unknown as D1DrizzleClientInterface);
34
+ };
35
+
21
36
  this.client = database as unknown as D1DrizzleClientInterface;
22
37
  }
23
38
 
@@ -46,7 +61,7 @@ export class D1DrizzleConnection implements DrizzleConnectionInterface
46
61
  /**
47
62
  * Returns the client.
48
63
  *
49
- * @returns {D1DrizzleClientInterface}
64
+ * @returns {D1DrizzleClientInterface} The D1 Drizzle client instance
50
65
  */
51
66
  public getClient(): D1DrizzleClientInterface
52
67
  {
@@ -1,3 +1,7 @@
1
1
  import { SqliteCoreDrizzleDataTypes } from '@drizzle-adapter/sqlite-core';
2
2
 
3
+ /**
4
+ * D1 data types implementation for Drizzle ORM.
5
+ * Extends the core SQLite data types with D1-specific functionality.
6
+ */
3
7
  export class D1DrizzleDataTypes extends SqliteCoreDrizzleDataTypes {}
@@ -1,7 +1,12 @@
1
1
  import type { DrizzleMigratorInterface, TypeDrizzleMigratorConfig } from '@drizzle-adapter/core';
2
2
  import { DrizzleD1Database } from 'drizzle-orm/d1/driver';
3
+
3
4
  import type { D1DrizzleClientInterface } from '../Interface';
4
5
 
6
+ /**
7
+ * D1 migrator implementation for Drizzle ORM.
8
+ * Handles database migrations for D1 databases.
9
+ */
5
10
  export class D1DrizzleMigrator implements DrizzleMigratorInterface
6
11
  {
7
12
  /**
@@ -14,7 +19,7 @@ export class D1DrizzleMigrator implements DrizzleMigratorInterface
14
19
  /**
15
20
  * Migrate the database.
16
21
  *
17
- * @param {DrizzleClientInterface} client The Drizzle client.
22
+ * @param {D1DrizzleClientInterface} client The Drizzle client.
18
23
  */
19
24
  public async migrate(client: D1DrizzleClientInterface): Promise<void>
20
25
  {
@@ -1,14 +1,19 @@
1
- import type { TypeD1DatabaseConfig } from '../Type/Types';
2
- import { D1DrizzleAdapter } from '../Adapter/D1DrizzleAdapter';
3
1
  import type { DrizzleAdapterFactoryInterface } from '@drizzle-adapter/core';
4
2
 
3
+ import { D1DrizzleAdapter } from '../Adapter/D1DrizzleAdapter';
4
+ import type { TypeD1DatabaseConfig } from '../Type/Types';
5
+
6
+ /**
7
+ * Factory for creating D1 adapter instances.
8
+ * Implements the DrizzleAdapterFactoryInterface for D1 database operations.
9
+ */
5
10
  export class D1DrizzleAdapterFactory implements DrizzleAdapterFactoryInterface
6
11
  {
7
12
  /**
8
13
  * Returns a adapter.
9
14
  *
10
- * @param {TypeD1DatabaseConfig} databaseConfig
11
- * @returns {D1DrizzleAdapter}
15
+ * @param {TypeD1DatabaseConfig} databaseConfig - The D1 database configuration
16
+ * @returns {D1DrizzleAdapter} A new D1 adapter instance
12
17
  */
13
18
  public create(databaseConfig: TypeD1DatabaseConfig): D1DrizzleAdapter
14
19
  {
@@ -1,13 +1,17 @@
1
1
  import type { DrizzleDataTypesFactoryInterface, TypeDrizzleDatabaseConfig } from '@drizzle-adapter/core';
2
2
  import { SqliteCoreDrizzleDataTypes } from '@drizzle-adapter/sqlite-core';
3
3
 
4
+ /**
5
+ * Factory for creating D1 data types instances.
6
+ * Implements the DrizzleDataTypesFactoryInterface for D1 database operations.
7
+ */
4
8
  export class D1DrizzleDataTypesFactory implements DrizzleDataTypesFactoryInterface
5
9
  {
6
10
  /**
7
11
  * Creates a new data types instance.
8
12
  *
9
13
  * @param {TypeDrizzleDatabaseConfig} _config - Not used in this implementation
10
- * @returns {SqliteCoreDrizzleDataTypes}
14
+ * @returns {SqliteCoreDrizzleDataTypes} A new SQLite core data types instance
11
15
  */
12
16
  public create(_config: TypeDrizzleDatabaseConfig): SqliteCoreDrizzleDataTypes
13
17
  {