binary.cjs 2.2 KB

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