varbinary.cjs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 varbinary_exports = {};
  20. __export(varbinary_exports, {
  21. MySqlVarBinary: () => MySqlVarBinary,
  22. MySqlVarBinaryBuilder: () => MySqlVarBinaryBuilder,
  23. varbinary: () => varbinary
  24. });
  25. module.exports = __toCommonJS(varbinary_exports);
  26. var import_entity = require("../../entity.cjs");
  27. var import_utils = require("../../utils.cjs");
  28. var import_common = require("./common.cjs");
  29. class MySqlVarBinaryBuilder extends import_common.MySqlColumnBuilder {
  30. static [import_entity.entityKind] = "MySqlVarBinaryBuilder";
  31. /** @internal */
  32. constructor(name, config) {
  33. super(name, "string", "MySqlVarBinary");
  34. this.config.length = config?.length;
  35. }
  36. /** @internal */
  37. build(table) {
  38. return new MySqlVarBinary(
  39. table,
  40. this.config
  41. );
  42. }
  43. }
  44. class MySqlVarBinary extends import_common.MySqlColumn {
  45. static [import_entity.entityKind] = "MySqlVarBinary";
  46. length = this.config.length;
  47. mapFromDriverValue(value) {
  48. if (typeof value === "string") return value;
  49. if (Buffer.isBuffer(value)) return value.toString();
  50. const str = [];
  51. for (const v of value) {
  52. str.push(v === 49 ? "1" : "0");
  53. }
  54. return str.join("");
  55. }
  56. getSQLType() {
  57. return this.length === void 0 ? `varbinary` : `varbinary(${this.length})`;
  58. }
  59. }
  60. function varbinary(a, b) {
  61. const { name, config } = (0, import_utils.getColumnNameAndConfig)(a, b);
  62. return new MySqlVarBinaryBuilder(name, config);
  63. }
  64. // Annotate the CommonJS export names for ESM import in node:
  65. 0 && (module.exports = {
  66. MySqlVarBinary,
  67. MySqlVarBinaryBuilder,
  68. varbinary
  69. });
  70. //# sourceMappingURL=varbinary.cjs.map