numeric.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import { entityKind } from "../../entity.js";
  2. import { getColumnNameAndConfig } from "../../utils.js";
  3. import { SQLiteColumn, SQLiteColumnBuilder } from "./common.js";
  4. class SQLiteNumericBuilder extends SQLiteColumnBuilder {
  5. static [entityKind] = "SQLiteNumericBuilder";
  6. constructor(name) {
  7. super(name, "string", "SQLiteNumeric");
  8. }
  9. /** @internal */
  10. build(table) {
  11. return new SQLiteNumeric(
  12. table,
  13. this.config
  14. );
  15. }
  16. }
  17. class SQLiteNumeric extends SQLiteColumn {
  18. static [entityKind] = "SQLiteNumeric";
  19. mapFromDriverValue(value) {
  20. if (typeof value === "string") return value;
  21. return String(value);
  22. }
  23. getSQLType() {
  24. return "numeric";
  25. }
  26. }
  27. class SQLiteNumericNumberBuilder extends SQLiteColumnBuilder {
  28. static [entityKind] = "SQLiteNumericNumberBuilder";
  29. constructor(name) {
  30. super(name, "number", "SQLiteNumericNumber");
  31. }
  32. /** @internal */
  33. build(table) {
  34. return new SQLiteNumericNumber(
  35. table,
  36. this.config
  37. );
  38. }
  39. }
  40. class SQLiteNumericNumber extends SQLiteColumn {
  41. static [entityKind] = "SQLiteNumericNumber";
  42. mapFromDriverValue(value) {
  43. if (typeof value === "number") return value;
  44. return Number(value);
  45. }
  46. mapToDriverValue = String;
  47. getSQLType() {
  48. return "numeric";
  49. }
  50. }
  51. class SQLiteNumericBigIntBuilder extends SQLiteColumnBuilder {
  52. static [entityKind] = "SQLiteNumericBigIntBuilder";
  53. constructor(name) {
  54. super(name, "bigint", "SQLiteNumericBigInt");
  55. }
  56. /** @internal */
  57. build(table) {
  58. return new SQLiteNumericBigInt(
  59. table,
  60. this.config
  61. );
  62. }
  63. }
  64. class SQLiteNumericBigInt extends SQLiteColumn {
  65. static [entityKind] = "SQLiteNumericBigInt";
  66. mapFromDriverValue = BigInt;
  67. mapToDriverValue = String;
  68. getSQLType() {
  69. return "numeric";
  70. }
  71. }
  72. function numeric(a, b) {
  73. const { name, config } = getColumnNameAndConfig(a, b);
  74. const mode = config?.mode;
  75. return mode === "number" ? new SQLiteNumericNumberBuilder(name) : mode === "bigint" ? new SQLiteNumericBigIntBuilder(name) : new SQLiteNumericBuilder(name);
  76. }
  77. export {
  78. SQLiteNumeric,
  79. SQLiteNumericBigInt,
  80. SQLiteNumericBigIntBuilder,
  81. SQLiteNumericBuilder,
  82. SQLiteNumericNumber,
  83. SQLiteNumericNumberBuilder,
  84. numeric
  85. };
  86. //# sourceMappingURL=numeric.js.map