bigserial.js 1.6 KB

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