blob.cjs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 blob_exports = {};
  20. __export(blob_exports, {
  21. SQLiteBigInt: () => SQLiteBigInt,
  22. SQLiteBigIntBuilder: () => SQLiteBigIntBuilder,
  23. SQLiteBlobBuffer: () => SQLiteBlobBuffer,
  24. SQLiteBlobBufferBuilder: () => SQLiteBlobBufferBuilder,
  25. SQLiteBlobJson: () => SQLiteBlobJson,
  26. SQLiteBlobJsonBuilder: () => SQLiteBlobJsonBuilder,
  27. blob: () => blob
  28. });
  29. module.exports = __toCommonJS(blob_exports);
  30. var import_entity = require("../../entity.cjs");
  31. var import_utils = require("../../utils.cjs");
  32. var import_common = require("./common.cjs");
  33. class SQLiteBigIntBuilder extends import_common.SQLiteColumnBuilder {
  34. static [import_entity.entityKind] = "SQLiteBigIntBuilder";
  35. constructor(name) {
  36. super(name, "bigint", "SQLiteBigInt");
  37. }
  38. /** @internal */
  39. build(table) {
  40. return new SQLiteBigInt(table, this.config);
  41. }
  42. }
  43. class SQLiteBigInt extends import_common.SQLiteColumn {
  44. static [import_entity.entityKind] = "SQLiteBigInt";
  45. getSQLType() {
  46. return "blob";
  47. }
  48. mapFromDriverValue(value) {
  49. if (typeof Buffer !== "undefined" && Buffer.from) {
  50. const buf = Buffer.isBuffer(value) ? value : value instanceof ArrayBuffer ? Buffer.from(value) : value.buffer ? Buffer.from(value.buffer, value.byteOffset, value.byteLength) : Buffer.from(value);
  51. return BigInt(buf.toString("utf8"));
  52. }
  53. return BigInt(import_utils.textDecoder.decode(value));
  54. }
  55. mapToDriverValue(value) {
  56. return Buffer.from(value.toString());
  57. }
  58. }
  59. class SQLiteBlobJsonBuilder extends import_common.SQLiteColumnBuilder {
  60. static [import_entity.entityKind] = "SQLiteBlobJsonBuilder";
  61. constructor(name) {
  62. super(name, "json", "SQLiteBlobJson");
  63. }
  64. /** @internal */
  65. build(table) {
  66. return new SQLiteBlobJson(
  67. table,
  68. this.config
  69. );
  70. }
  71. }
  72. class SQLiteBlobJson extends import_common.SQLiteColumn {
  73. static [import_entity.entityKind] = "SQLiteBlobJson";
  74. getSQLType() {
  75. return "blob";
  76. }
  77. mapFromDriverValue(value) {
  78. if (typeof Buffer !== "undefined" && Buffer.from) {
  79. const buf = Buffer.isBuffer(value) ? value : value instanceof ArrayBuffer ? Buffer.from(value) : value.buffer ? Buffer.from(value.buffer, value.byteOffset, value.byteLength) : Buffer.from(value);
  80. return JSON.parse(buf.toString("utf8"));
  81. }
  82. return JSON.parse(import_utils.textDecoder.decode(value));
  83. }
  84. mapToDriverValue(value) {
  85. return Buffer.from(JSON.stringify(value));
  86. }
  87. }
  88. class SQLiteBlobBufferBuilder extends import_common.SQLiteColumnBuilder {
  89. static [import_entity.entityKind] = "SQLiteBlobBufferBuilder";
  90. constructor(name) {
  91. super(name, "buffer", "SQLiteBlobBuffer");
  92. }
  93. /** @internal */
  94. build(table) {
  95. return new SQLiteBlobBuffer(table, this.config);
  96. }
  97. }
  98. class SQLiteBlobBuffer extends import_common.SQLiteColumn {
  99. static [import_entity.entityKind] = "SQLiteBlobBuffer";
  100. mapFromDriverValue(value) {
  101. if (Buffer.isBuffer(value)) {
  102. return value;
  103. }
  104. return Buffer.from(value);
  105. }
  106. getSQLType() {
  107. return "blob";
  108. }
  109. }
  110. function blob(a, b) {
  111. const { name, config } = (0, import_utils.getColumnNameAndConfig)(a, b);
  112. if (config?.mode === "json") {
  113. return new SQLiteBlobJsonBuilder(name);
  114. }
  115. if (config?.mode === "bigint") {
  116. return new SQLiteBigIntBuilder(name);
  117. }
  118. return new SQLiteBlobBufferBuilder(name);
  119. }
  120. // Annotate the CommonJS export names for ESM import in node:
  121. 0 && (module.exports = {
  122. SQLiteBigInt,
  123. SQLiteBigIntBuilder,
  124. SQLiteBlobBuffer,
  125. SQLiteBlobBufferBuilder,
  126. SQLiteBlobJson,
  127. SQLiteBlobJsonBuilder,
  128. blob
  129. });
  130. //# sourceMappingURL=blob.cjs.map