bigint.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { entityKind } from "../../entity.js";
  2. import { getColumnNameAndConfig } from "../../utils.js";
  3. import { PgColumn } from "./common.js";
  4. import { PgIntColumnBaseBuilder } from "./int.common.js";
  5. class PgBigInt53Builder extends PgIntColumnBaseBuilder {
  6. static [entityKind] = "PgBigInt53Builder";
  7. constructor(name) {
  8. super(name, "number", "PgBigInt53");
  9. }
  10. /** @internal */
  11. build(table) {
  12. return new PgBigInt53(table, this.config);
  13. }
  14. }
  15. class PgBigInt53 extends PgColumn {
  16. static [entityKind] = "PgBigInt53";
  17. getSQLType() {
  18. return "bigint";
  19. }
  20. mapFromDriverValue(value) {
  21. if (typeof value === "number") {
  22. return value;
  23. }
  24. return Number(value);
  25. }
  26. }
  27. class PgBigInt64Builder extends PgIntColumnBaseBuilder {
  28. static [entityKind] = "PgBigInt64Builder";
  29. constructor(name) {
  30. super(name, "bigint", "PgBigInt64");
  31. }
  32. /** @internal */
  33. build(table) {
  34. return new PgBigInt64(
  35. table,
  36. this.config
  37. );
  38. }
  39. }
  40. class PgBigInt64 extends PgColumn {
  41. static [entityKind] = "PgBigInt64";
  42. getSQLType() {
  43. return "bigint";
  44. }
  45. // eslint-disable-next-line unicorn/prefer-native-coercion-functions
  46. mapFromDriverValue(value) {
  47. return BigInt(value);
  48. }
  49. }
  50. function bigint(a, b) {
  51. const { name, config } = getColumnNameAndConfig(a, b);
  52. if (config.mode === "number") {
  53. return new PgBigInt53Builder(name);
  54. }
  55. return new PgBigInt64Builder(name);
  56. }
  57. export {
  58. PgBigInt53,
  59. PgBigInt53Builder,
  60. PgBigInt64,
  61. PgBigInt64Builder,
  62. bigint
  63. };
  64. //# sourceMappingURL=bigint.js.map