int.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import { entityKind } from "../../entity.js";
  2. import { getColumnNameAndConfig } from "../../utils.js";
  3. import { MySqlColumnBuilderWithAutoIncrement, MySqlColumnWithAutoIncrement } from "./common.js";
  4. class MySqlIntBuilder extends MySqlColumnBuilderWithAutoIncrement {
  5. static [entityKind] = "MySqlIntBuilder";
  6. constructor(name, config) {
  7. super(name, "number", "MySqlInt");
  8. this.config.unsigned = config ? config.unsigned : false;
  9. }
  10. /** @internal */
  11. build(table) {
  12. return new MySqlInt(table, this.config);
  13. }
  14. }
  15. class MySqlInt extends MySqlColumnWithAutoIncrement {
  16. static [entityKind] = "MySqlInt";
  17. getSQLType() {
  18. return `int${this.config.unsigned ? " unsigned" : ""}`;
  19. }
  20. mapFromDriverValue(value) {
  21. if (typeof value === "string") {
  22. return Number(value);
  23. }
  24. return value;
  25. }
  26. }
  27. function int(a, b) {
  28. const { name, config } = getColumnNameAndConfig(a, b);
  29. return new MySqlIntBuilder(name, config);
  30. }
  31. export {
  32. MySqlInt,
  33. MySqlIntBuilder,
  34. int
  35. };
  36. //# sourceMappingURL=int.js.map