bigint.js 1.9 KB

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