point.cjs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 point_exports = {};
  20. __export(point_exports, {
  21. PgPointObject: () => PgPointObject,
  22. PgPointObjectBuilder: () => PgPointObjectBuilder,
  23. PgPointTuple: () => PgPointTuple,
  24. PgPointTupleBuilder: () => PgPointTupleBuilder,
  25. point: () => point
  26. });
  27. module.exports = __toCommonJS(point_exports);
  28. var import_entity = require("../../entity.cjs");
  29. var import_utils = require("../../utils.cjs");
  30. var import_common = require("./common.cjs");
  31. class PgPointTupleBuilder extends import_common.PgColumnBuilder {
  32. static [import_entity.entityKind] = "PgPointTupleBuilder";
  33. constructor(name) {
  34. super(name, "array", "PgPointTuple");
  35. }
  36. /** @internal */
  37. build(table) {
  38. return new PgPointTuple(
  39. table,
  40. this.config
  41. );
  42. }
  43. }
  44. class PgPointTuple extends import_common.PgColumn {
  45. static [import_entity.entityKind] = "PgPointTuple";
  46. getSQLType() {
  47. return "point";
  48. }
  49. mapFromDriverValue(value) {
  50. if (typeof value === "string") {
  51. const [x, y] = value.slice(1, -1).split(",");
  52. return [Number.parseFloat(x), Number.parseFloat(y)];
  53. }
  54. return [value.x, value.y];
  55. }
  56. mapToDriverValue(value) {
  57. return `(${value[0]},${value[1]})`;
  58. }
  59. }
  60. class PgPointObjectBuilder extends import_common.PgColumnBuilder {
  61. static [import_entity.entityKind] = "PgPointObjectBuilder";
  62. constructor(name) {
  63. super(name, "json", "PgPointObject");
  64. }
  65. /** @internal */
  66. build(table) {
  67. return new PgPointObject(
  68. table,
  69. this.config
  70. );
  71. }
  72. }
  73. class PgPointObject extends import_common.PgColumn {
  74. static [import_entity.entityKind] = "PgPointObject";
  75. getSQLType() {
  76. return "point";
  77. }
  78. mapFromDriverValue(value) {
  79. if (typeof value === "string") {
  80. const [x, y] = value.slice(1, -1).split(",");
  81. return { x: Number.parseFloat(x), y: Number.parseFloat(y) };
  82. }
  83. return value;
  84. }
  85. mapToDriverValue(value) {
  86. return `(${value.x},${value.y})`;
  87. }
  88. }
  89. function point(a, b) {
  90. const { name, config } = (0, import_utils.getColumnNameAndConfig)(a, b);
  91. if (!config?.mode || config.mode === "tuple") {
  92. return new PgPointTupleBuilder(name);
  93. }
  94. return new PgPointObjectBuilder(name);
  95. }
  96. // Annotate the CommonJS export names for ESM import in node:
  97. 0 && (module.exports = {
  98. PgPointObject,
  99. PgPointObjectBuilder,
  100. PgPointTuple,
  101. PgPointTupleBuilder,
  102. point
  103. });
  104. //# sourceMappingURL=point.cjs.map