smallint.js 1.1 KB

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