double.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { entityKind } from "../../entity.js";
  2. import { getColumnNameAndConfig } from "../../utils.js";
  3. import { MySqlColumnBuilderWithAutoIncrement, MySqlColumnWithAutoIncrement } from "./common.js";
  4. class MySqlDoubleBuilder extends MySqlColumnBuilderWithAutoIncrement {
  5. static [entityKind] = "MySqlDoubleBuilder";
  6. constructor(name, config) {
  7. super(name, "number", "MySqlDouble");
  8. this.config.precision = config?.precision;
  9. this.config.scale = config?.scale;
  10. this.config.unsigned = config?.unsigned;
  11. }
  12. /** @internal */
  13. build(table) {
  14. return new MySqlDouble(table, this.config);
  15. }
  16. }
  17. class MySqlDouble extends MySqlColumnWithAutoIncrement {
  18. static [entityKind] = "MySqlDouble";
  19. precision = this.config.precision;
  20. scale = this.config.scale;
  21. unsigned = this.config.unsigned;
  22. getSQLType() {
  23. let type = "";
  24. if (this.precision !== void 0 && this.scale !== void 0) {
  25. type += `double(${this.precision},${this.scale})`;
  26. } else if (this.precision === void 0) {
  27. type += "double";
  28. } else {
  29. type += `double(${this.precision})`;
  30. }
  31. return this.unsigned ? `${type} unsigned` : type;
  32. }
  33. }
  34. function double(a, b) {
  35. const { name, config } = getColumnNameAndConfig(a, b);
  36. return new MySqlDoubleBuilder(name, config);
  37. }
  38. export {
  39. MySqlDouble,
  40. MySqlDoubleBuilder,
  41. double
  42. };
  43. //# sourceMappingURL=double.js.map