line.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import { entityKind } from "../../entity.js";
  2. import { getColumnNameAndConfig } from "../../utils.js";
  3. import { PgColumn, PgColumnBuilder } from "./common.js";
  4. class PgLineBuilder extends PgColumnBuilder {
  5. static [entityKind] = "PgLineBuilder";
  6. constructor(name) {
  7. super(name, "array", "PgLine");
  8. }
  9. /** @internal */
  10. build(table) {
  11. return new PgLineTuple(
  12. table,
  13. this.config
  14. );
  15. }
  16. }
  17. class PgLineTuple extends PgColumn {
  18. static [entityKind] = "PgLine";
  19. getSQLType() {
  20. return "line";
  21. }
  22. mapFromDriverValue(value) {
  23. const [a, b, c] = value.slice(1, -1).split(",");
  24. return [Number.parseFloat(a), Number.parseFloat(b), Number.parseFloat(c)];
  25. }
  26. mapToDriverValue(value) {
  27. return `{${value[0]},${value[1]},${value[2]}}`;
  28. }
  29. }
  30. class PgLineABCBuilder extends PgColumnBuilder {
  31. static [entityKind] = "PgLineABCBuilder";
  32. constructor(name) {
  33. super(name, "json", "PgLineABC");
  34. }
  35. /** @internal */
  36. build(table) {
  37. return new PgLineABC(
  38. table,
  39. this.config
  40. );
  41. }
  42. }
  43. class PgLineABC extends PgColumn {
  44. static [entityKind] = "PgLineABC";
  45. getSQLType() {
  46. return "line";
  47. }
  48. mapFromDriverValue(value) {
  49. const [a, b, c] = value.slice(1, -1).split(",");
  50. return { a: Number.parseFloat(a), b: Number.parseFloat(b), c: Number.parseFloat(c) };
  51. }
  52. mapToDriverValue(value) {
  53. return `{${value.a},${value.b},${value.c}}`;
  54. }
  55. }
  56. function line(a, b) {
  57. const { name, config } = getColumnNameAndConfig(a, b);
  58. if (!config?.mode || config.mode === "tuple") {
  59. return new PgLineBuilder(name);
  60. }
  61. return new PgLineABCBuilder(name);
  62. }
  63. export {
  64. PgLineABC,
  65. PgLineABCBuilder,
  66. PgLineBuilder,
  67. PgLineTuple,
  68. line
  69. };
  70. //# sourceMappingURL=line.js.map