indexes.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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] = "SQLiteIndexBuilderOn";
  8. on(...columns) {
  9. return new IndexBuilder(this.name, columns, this.unique);
  10. }
  11. }
  12. class IndexBuilder {
  13. static [entityKind] = "SQLiteIndexBuilder";
  14. /** @internal */
  15. config;
  16. constructor(name, columns, unique) {
  17. this.config = {
  18. name,
  19. columns,
  20. unique,
  21. where: void 0
  22. };
  23. }
  24. /**
  25. * Condition for partial index.
  26. */
  27. where(condition) {
  28. this.config.where = condition;
  29. return this;
  30. }
  31. /** @internal */
  32. build(table) {
  33. return new Index(this.config, table);
  34. }
  35. }
  36. class Index {
  37. static [entityKind] = "SQLiteIndex";
  38. config;
  39. constructor(config, table) {
  40. this.config = { ...config, table };
  41. }
  42. }
  43. function index(name) {
  44. return new IndexBuilderOn(name, false);
  45. }
  46. function uniqueIndex(name) {
  47. return new IndexBuilderOn(name, true);
  48. }
  49. export {
  50. Index,
  51. IndexBuilder,
  52. IndexBuilderOn,
  53. index,
  54. uniqueIndex
  55. };
  56. //# sourceMappingURL=indexes.js.map