driver.cjs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. "use strict";
  2. var __defProp = Object.defineProperty;
  3. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  4. var __getOwnPropNames = Object.getOwnPropertyNames;
  5. var __hasOwnProp = Object.prototype.hasOwnProperty;
  6. var __export = (target, all) => {
  7. for (var name in all)
  8. __defProp(target, name, { get: all[name], enumerable: true });
  9. };
  10. var __copyProps = (to, from, except, desc) => {
  11. if (from && typeof from === "object" || typeof from === "function") {
  12. for (let key of __getOwnPropNames(from))
  13. if (!__hasOwnProp.call(to, key) && key !== except)
  14. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  15. }
  16. return to;
  17. };
  18. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  19. var driver_exports = {};
  20. __export(driver_exports, {
  21. DrizzleD1Database: () => DrizzleD1Database,
  22. drizzle: () => drizzle
  23. });
  24. module.exports = __toCommonJS(driver_exports);
  25. var import_entity = require("../entity.cjs");
  26. var import_logger = require("../logger.cjs");
  27. var import_relations = require("../relations.cjs");
  28. var import_db = require("../sqlite-core/db.cjs");
  29. var import_dialect = require("../sqlite-core/dialect.cjs");
  30. var import_session = require("./session.cjs");
  31. class DrizzleD1Database extends import_db.BaseSQLiteDatabase {
  32. static [import_entity.entityKind] = "D1Database";
  33. async batch(batch) {
  34. return this.session.batch(batch);
  35. }
  36. }
  37. function drizzle(client, config = {}) {
  38. const dialect = new import_dialect.SQLiteAsyncDialect({ casing: config.casing });
  39. let logger;
  40. if (config.logger === true) {
  41. logger = new import_logger.DefaultLogger();
  42. } else if (config.logger !== false) {
  43. logger = config.logger;
  44. }
  45. let schema;
  46. if (config.schema) {
  47. const tablesConfig = (0, import_relations.extractTablesRelationalConfig)(
  48. config.schema,
  49. import_relations.createTableRelationsHelpers
  50. );
  51. schema = {
  52. fullSchema: config.schema,
  53. schema: tablesConfig.tables,
  54. tableNamesMap: tablesConfig.tableNamesMap
  55. };
  56. }
  57. const session = new import_session.SQLiteD1Session(client, dialect, schema, { logger, cache: config.cache });
  58. const db = new DrizzleD1Database("async", dialect, session, schema);
  59. db.$client = client;
  60. db.$cache = config.cache;
  61. if (db.$cache) {
  62. db.$cache["invalidate"] = config.cache?.onMutate;
  63. }
  64. return db;
  65. }
  66. // Annotate the CommonJS export names for ESM import in node:
  67. 0 && (module.exports = {
  68. DrizzleD1Database,
  69. drizzle
  70. });
  71. //# sourceMappingURL=driver.cjs.map