indexes.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { entityKind } from "../entity.js";
  2. class IndexBuilderOn {
  3. constructor(name, unique) {
  4. this.name = name;
  5. this.unique = unique;
  6. }
  7. static [entityKind] = "MySqlIndexBuilderOn";
  8. on(...columns) {
  9. return new IndexBuilder(this.name, columns, this.unique);
  10. }
  11. }
  12. class IndexBuilder {
  13. static [entityKind] = "MySqlIndexBuilder";
  14. /** @internal */
  15. config;
  16. constructor(name, columns, unique) {
  17. this.config = {
  18. name,
  19. columns,
  20. unique
  21. };
  22. }
  23. using(using) {
  24. this.config.using = using;
  25. return this;
  26. }
  27. algorithm(algorithm) {
  28. this.config.algorithm = algorithm;
  29. return this;
  30. }
  31. lock(lock) {
  32. this.config.lock = lock;
  33. return this;
  34. }
  35. /** @internal */
  36. build(table) {
  37. return new Index(this.config, table);
  38. }
  39. }
  40. class Index {
  41. static [entityKind] = "MySqlIndex";
  42. config;
  43. constructor(config, table) {
  44. this.config = { ...config, table };
  45. }
  46. }
  47. function index(name) {
  48. return new IndexBuilderOn(name, false);
  49. }
  50. function uniqueIndex(name) {
  51. return new IndexBuilderOn(name, true);
  52. }
  53. export {
  54. Index,
  55. IndexBuilder,
  56. IndexBuilderOn,
  57. index,
  58. uniqueIndex
  59. };
  60. //# sourceMappingURL=indexes.js.map