metal-orm 1.0.15 → 1.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/README.md +34 -27
  2. package/dist/decorators/index.cjs +339 -153
  3. package/dist/decorators/index.cjs.map +1 -1
  4. package/dist/decorators/index.d.cts +1 -5
  5. package/dist/decorators/index.d.ts +1 -5
  6. package/dist/decorators/index.js +339 -153
  7. package/dist/decorators/index.js.map +1 -1
  8. package/dist/index.cjs +838 -484
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.d.cts +17 -14
  11. package/dist/index.d.ts +17 -14
  12. package/dist/index.js +833 -483
  13. package/dist/index.js.map +1 -1
  14. package/dist/{select-Bkv8g8u_.d.cts → select-BKZrMRCQ.d.cts} +363 -28
  15. package/dist/{select-Bkv8g8u_.d.ts → select-BKZrMRCQ.d.ts} +363 -28
  16. package/package.json +1 -1
  17. package/src/codegen/naming-strategy.ts +64 -0
  18. package/src/codegen/typescript.ts +48 -53
  19. package/src/core/ddl/schema-generator.ts +3 -2
  20. package/src/core/ddl/schema-introspect.ts +1 -1
  21. package/src/core/dialect/abstract.ts +28 -0
  22. package/src/decorators/column.ts +13 -4
  23. package/src/index.ts +8 -1
  24. package/src/orm/entity-context.ts +30 -0
  25. package/src/orm/entity-meta.ts +2 -2
  26. package/src/orm/entity-metadata.ts +1 -6
  27. package/src/orm/entity.ts +88 -88
  28. package/src/orm/execute.ts +42 -25
  29. package/src/orm/execution-context.ts +12 -0
  30. package/src/orm/hydration-context.ts +14 -0
  31. package/src/orm/identity-map.ts +4 -0
  32. package/src/orm/interceptor-pipeline.ts +29 -0
  33. package/src/orm/lazy-batch.ts +6 -6
  34. package/src/orm/orm-session.ts +234 -0
  35. package/src/orm/orm.ts +58 -0
  36. package/src/orm/relation-change-processor.ts +5 -1
  37. package/src/orm/relations/belongs-to.ts +45 -44
  38. package/src/orm/relations/has-many.ts +44 -43
  39. package/src/orm/relations/has-one.ts +140 -139
  40. package/src/orm/relations/many-to-many.ts +46 -45
  41. package/src/orm/unit-of-work.ts +6 -1
  42. package/src/query-builder/select.ts +509 -3
  43. package/src/orm/orm-context.ts +0 -159
@@ -1023,6 +1023,12 @@ declare abstract class Dialect implements SelectCompiler, InsertCompiler, Update
1023
1023
  private readonly operandCompilers;
1024
1024
  protected readonly functionStrategy: FunctionStrategy;
1025
1025
  protected constructor(functionStrategy?: FunctionStrategy);
1026
+ /**
1027
+ * Creates a new Dialect instance (for testing purposes)
1028
+ * @param functionStrategy - Optional function strategy
1029
+ * @returns New Dialect instance
1030
+ */
1031
+ static create(functionStrategy?: FunctionStrategy): Dialect;
1026
1032
  /**
1027
1033
  * Registers an expression compiler for a specific node type
1028
1034
  * @param type - Expression node type
@@ -1577,6 +1583,65 @@ interface SimpleQueryRunner {
1577
1583
  */
1578
1584
  declare function createExecutorFromQueryRunner(runner: SimpleQueryRunner): DbExecutor;
1579
1585
 
1586
+ type EntityConstructor = new (...args: any[]) => any;
1587
+ type EntityOrTableTarget = EntityConstructor | TableDef;
1588
+ type EntityOrTableTargetResolver = EntityOrTableTarget | (() => EntityOrTableTarget);
1589
+
1590
+ /**
1591
+ * Strategy interface for converting database names to TypeScript identifiers
1592
+ */
1593
+ interface NamingStrategy {
1594
+ /**
1595
+ * Converts a table name to a TypeScript symbol name
1596
+ * @param table - Table node, function table node, or name
1597
+ * @returns Valid TypeScript identifier
1598
+ */
1599
+ tableToSymbol(table: TableNode | FunctionTableNode | string): string;
1600
+ /**
1601
+ * Converts a column reference to a property name
1602
+ * @param column - Column node
1603
+ * @returns Valid TypeScript property name
1604
+ */
1605
+ columnToProperty(column: ColumnNode): string;
1606
+ }
1607
+
1608
+ interface QueryContext {
1609
+ sql: string;
1610
+ params: unknown[];
1611
+ }
1612
+ type QueryInterceptor = (ctx: QueryContext, next: () => Promise<QueryResult[]>) => Promise<QueryResult[]>;
1613
+ declare class InterceptorPipeline {
1614
+ private interceptors;
1615
+ use(interceptor: QueryInterceptor): void;
1616
+ run(ctx: QueryContext, executor: DbExecutor): Promise<QueryResult[]>;
1617
+ }
1618
+
1619
+ interface OrmOptions {
1620
+ dialect: Dialect;
1621
+ executorFactory: DbExecutorFactory;
1622
+ interceptors?: InterceptorPipeline;
1623
+ namingStrategy?: NamingStrategy;
1624
+ }
1625
+ interface DbExecutorFactory {
1626
+ createExecutor(options?: {
1627
+ tx?: ExternalTransaction;
1628
+ }): DbExecutor;
1629
+ createTransactionalExecutor(): DbExecutor;
1630
+ }
1631
+ interface ExternalTransaction {
1632
+ }
1633
+ declare class Orm {
1634
+ readonly dialect: Dialect;
1635
+ readonly interceptors: InterceptorPipeline;
1636
+ readonly namingStrategy: NamingStrategy;
1637
+ private readonly executorFactory;
1638
+ constructor(opts: OrmOptions);
1639
+ createSession(options?: {
1640
+ tx?: ExternalTransaction;
1641
+ }): OrmSession;
1642
+ transaction<T>(fn: (session: OrmSession) => Promise<T>): Promise<T>;
1643
+ }
1644
+
1580
1645
  declare enum EntityStatus {
1581
1646
  New = "new",
1582
1647
  Managed = "managed",
@@ -1605,63 +1670,184 @@ type RelationChange<T> = {
1605
1670
  kind: 'detach';
1606
1671
  entity: T;
1607
1672
  };
1673
+ interface RelationChangeEntry {
1674
+ root: any;
1675
+ relationKey: RelationKey;
1676
+ rootTable: TableDef;
1677
+ relationName: string;
1678
+ relation: RelationDef;
1679
+ change: RelationChange<any>;
1680
+ }
1608
1681
  interface HasDomainEvents {
1609
1682
  domainEvents?: any[];
1610
1683
  }
1611
1684
 
1612
- type DomainEventHandler$1<Context> = (event: any, ctx: Context) => Promise<void> | void;
1685
+ declare class IdentityMap {
1686
+ private readonly buckets;
1687
+ get bucketsMap(): Map<string, Map<string, TrackedEntity>>;
1688
+ getEntity(table: TableDef, pk: string | number): any | undefined;
1689
+ register(tracked: TrackedEntity): void;
1690
+ remove(tracked: TrackedEntity): void;
1691
+ getEntitiesForTable(table: TableDef): TrackedEntity[];
1692
+ clear(): void;
1693
+ private toIdentityKey;
1694
+ }
1695
+
1696
+ declare class UnitOfWork {
1697
+ private readonly dialect;
1698
+ private readonly executor;
1699
+ private readonly identityMap;
1700
+ private readonly hookContext;
1701
+ private readonly trackedEntities;
1702
+ constructor(dialect: Dialect, executor: DbExecutor, identityMap: IdentityMap, hookContext: () => unknown);
1703
+ get identityBuckets(): Map<string, Map<string, TrackedEntity>>;
1704
+ getTracked(): TrackedEntity[];
1705
+ getEntity(table: TableDef, pk: string | number): any | undefined;
1706
+ getEntitiesForTable(table: TableDef): TrackedEntity[];
1707
+ findTracked(entity: any): TrackedEntity | undefined;
1708
+ setEntity(table: TableDef, pk: string | number, entity: any): void;
1709
+ trackNew(table: TableDef, entity: any, pk?: string | number): void;
1710
+ trackManaged(table: TableDef, pk: string | number, entity: any): void;
1711
+ markDirty(entity: any): void;
1712
+ markRemoved(entity: any): void;
1713
+ flush(): Promise<void>;
1714
+ reset(): void;
1715
+ private flushInsert;
1716
+ private flushUpdate;
1717
+ private flushDelete;
1718
+ private runHook;
1719
+ private computeChanges;
1720
+ private extractColumns;
1721
+ private executeCompiled;
1722
+ private getReturningColumns;
1723
+ private applyReturningResults;
1724
+ private normalizeColumnName;
1725
+ private registerIdentity;
1726
+ private createSnapshot;
1727
+ private getPrimaryKeyValue;
1728
+ }
1729
+
1730
+ type DomainEventHandler<Context> = (event: any, ctx: Context) => Promise<void> | void;
1731
+ declare class DomainEventBus<Context> {
1732
+ private readonly handlers;
1733
+ constructor(initialHandlers?: Record<string, DomainEventHandler<Context>[]>);
1734
+ register(name: string, handler: DomainEventHandler<Context>): void;
1735
+ dispatch(trackedEntities: Iterable<TrackedEntity>, ctx: Context): Promise<void>;
1736
+ private getEventName;
1737
+ }
1613
1738
  declare const addDomainEvent: (entity: HasDomainEvents, event: any) => void;
1614
1739
 
1740
+ declare class RelationChangeProcessor {
1741
+ private readonly unitOfWork;
1742
+ private readonly dialect;
1743
+ private readonly executor;
1744
+ private readonly relationChanges;
1745
+ constructor(unitOfWork: UnitOfWork, dialect: Dialect, executor: DbExecutor);
1746
+ registerChange(entry: RelationChangeEntry): void;
1747
+ reset(): void;
1748
+ process(): Promise<void>;
1749
+ private handleHasManyChange;
1750
+ private handleHasOneChange;
1751
+ private handleBelongsToChange;
1752
+ private handleBelongsToManyChange;
1753
+ private assignHasManyForeignKey;
1754
+ private detachHasManyChild;
1755
+ private assignHasOneForeignKey;
1756
+ private detachHasOneChild;
1757
+ private insertPivotRow;
1758
+ private deletePivotRow;
1759
+ private resolvePrimaryKeyValue;
1760
+ }
1761
+
1615
1762
  interface QueryLogEntry {
1616
1763
  sql: string;
1617
1764
  params?: unknown[];
1618
1765
  }
1619
1766
  type QueryLogger = (entry: QueryLogEntry) => void;
1767
+ declare const createQueryLoggingExecutor: (executor: DbExecutor, logger?: QueryLogger) => DbExecutor;
1620
1768
 
1621
- interface OrmInterceptor {
1622
- beforeFlush?(ctx: OrmContext): Promise<void> | void;
1623
- afterFlush?(ctx: OrmContext): Promise<void> | void;
1769
+ interface ExecutionContext {
1770
+ dialect: Dialect;
1771
+ executor: DbExecutor;
1772
+ interceptors: InterceptorPipeline;
1624
1773
  }
1625
- type DomainEventHandler = DomainEventHandler$1<OrmContext>;
1626
- interface OrmContextOptions {
1774
+
1775
+ interface EntityContext {
1627
1776
  dialect: Dialect;
1628
1777
  executor: DbExecutor;
1629
- interceptors?: OrmInterceptor[];
1630
- domainEventHandlers?: Record<string, DomainEventHandler[]>;
1631
- queryLogger?: QueryLogger;
1778
+ getEntity(table: TableDef, pk: any): any;
1779
+ setEntity(table: TableDef, pk: any, entity: any): void;
1780
+ trackNew(table: TableDef, entity: any, pk?: any): void;
1781
+ trackManaged(table: TableDef, pk: any, entity: any): void;
1782
+ markDirty(entity: any): void;
1783
+ markRemoved(entity: any): void;
1784
+ getEntitiesForTable(table: TableDef): TrackedEntity[];
1785
+ registerRelationChange(root: any, relationKey: RelationKey, rootTable: TableDef, relationName: string, relation: RelationDef, change: RelationChange<any>): void;
1632
1786
  }
1633
- declare class OrmContext {
1634
- private readonly options;
1635
- private readonly identityMap;
1636
- private readonly executorWithLogging;
1637
- private readonly unitOfWork;
1638
- private readonly relationChanges;
1787
+
1788
+ interface HydrationContext {
1789
+ identityMap: IdentityMap;
1790
+ unitOfWork: UnitOfWork;
1791
+ domainEvents: DomainEventBus<any>;
1792
+ relationChanges: RelationChangeProcessor;
1793
+ entityContext: EntityContext;
1794
+ }
1795
+
1796
+ interface OrmInterceptor {
1797
+ beforeFlush?(ctx: EntityContext): Promise<void> | void;
1798
+ afterFlush?(ctx: EntityContext): Promise<void> | void;
1799
+ }
1800
+ interface OrmSessionOptions {
1801
+ orm: Orm;
1802
+ executor: DbExecutor;
1803
+ queryLogger?: QueryLogger;
1804
+ interceptors?: OrmInterceptor[];
1805
+ domainEventHandlers?: Record<string, DomainEventHandler<OrmSession>[]>;
1806
+ }
1807
+ declare class OrmSession implements EntityContext {
1808
+ readonly orm: Orm;
1809
+ readonly executor: DbExecutor;
1810
+ readonly identityMap: IdentityMap;
1811
+ readonly unitOfWork: UnitOfWork;
1812
+ readonly domainEvents: DomainEventBus<OrmSession>;
1813
+ readonly relationChanges: RelationChangeProcessor;
1639
1814
  private readonly interceptors;
1640
- private readonly domainEvents;
1641
- constructor(options: OrmContextOptions);
1815
+ constructor(opts: OrmSessionOptions);
1642
1816
  get dialect(): Dialect;
1643
- get executor(): DbExecutor;
1644
1817
  get identityBuckets(): Map<string, Map<string, TrackedEntity>>;
1645
1818
  get tracked(): TrackedEntity[];
1646
- getEntity(table: TableDef, pk: string | number): any | undefined;
1647
- setEntity(table: TableDef, pk: string | number, entity: any): void;
1648
- trackNew(table: TableDef, entity: any, pk?: string | number): void;
1649
- trackManaged(table: TableDef, pk: string | number, entity: any): void;
1819
+ getEntity(table: TableDef, pk: any): any | undefined;
1820
+ setEntity(table: TableDef, pk: any, entity: any): void;
1821
+ trackNew(table: TableDef, entity: any, pk?: any): void;
1822
+ trackManaged(table: TableDef, pk: any, entity: any): void;
1650
1823
  markDirty(entity: any): void;
1651
1824
  markRemoved(entity: any): void;
1652
- registerRelationChange(root: any, relationKey: RelationKey, rootTable: TableDef, relationName: string, relation: RelationDef, change: RelationChange<any>): void;
1653
- registerInterceptor(interceptor: OrmInterceptor): void;
1654
- registerDomainEventHandler(name: string, handler: DomainEventHandler): void;
1655
- saveChanges(): Promise<void>;
1825
+ registerRelationChange: (root: any, relationKey: RelationKey, rootTable: TableDef, relationName: string, relation: RelationDef, change: RelationChange<any>) => void;
1656
1826
  getEntitiesForTable(table: TableDef): TrackedEntity[];
1827
+ registerInterceptor(interceptor: OrmInterceptor): void;
1828
+ registerDomainEventHandler(name: string, handler: DomainEventHandler<OrmSession>): void;
1829
+ find<TTable extends TableDef>(entityClass: EntityConstructor, id: any): Promise<Entity<TTable> | null>;
1830
+ findOne<TTable extends TableDef>(qb: SelectQueryBuilder<any, TTable>): Promise<Entity<TTable> | null>;
1831
+ findMany<TTable extends TableDef>(qb: SelectQueryBuilder<any, TTable>): Promise<Entity<TTable>[]>;
1832
+ persist(entity: object): Promise<void>;
1833
+ remove(entity: object): Promise<void>;
1834
+ flush(): Promise<void>;
1835
+ commit(): Promise<void>;
1836
+ rollback(): Promise<void>;
1837
+ getExecutionContext(): ExecutionContext;
1838
+ getHydrationContext(): HydrationContext;
1657
1839
  }
1658
1840
 
1659
1841
  type SelectDialectInput = Dialect | DialectKey;
1660
1842
 
1661
1843
  /**
1844
+
1662
1845
  * Main query builder class for constructing SQL SELECT queries
1846
+
1663
1847
  * @typeParam T - Result type for projections (unused)
1848
+
1664
1849
  * @typeParam TTable - Table definition being queried
1850
+
1665
1851
  */
1666
1852
  declare class SelectQueryBuilder<T = any, TTable extends TableDef = TableDef> {
1667
1853
  private readonly env;
@@ -1670,11 +1856,17 @@ declare class SelectQueryBuilder<T = any, TTable extends TableDef = TableDef> {
1670
1856
  private readonly relationManager;
1671
1857
  private readonly lazyRelations;
1672
1858
  /**
1859
+
1673
1860
  * Creates a new SelectQueryBuilder instance
1861
+
1674
1862
  * @param table - Table definition to query
1863
+
1675
1864
  * @param state - Optional initial query state
1865
+
1676
1866
  * @param hydration - Optional hydration manager
1867
+
1677
1868
  * @param dependencies - Optional query builder dependencies
1869
+
1678
1870
  */
1679
1871
  constructor(table: TTable, state?: SelectQueryState, hydration?: HydrationManager, dependencies?: Partial<SelectQueryBuilderDependencies>, lazyRelations?: Set<string>);
1680
1872
  private clone;
@@ -1684,215 +1876,358 @@ declare class SelectQueryBuilder<T = any, TTable extends TableDef = TableDef> {
1684
1876
  private applyJoin;
1685
1877
  private applySetOperation;
1686
1878
  /**
1879
+
1687
1880
  * Selects specific columns for the query
1881
+
1688
1882
  * @param columns - Record of column definitions, function nodes, case expressions, or window functions
1883
+
1689
1884
  * @returns New query builder instance with selected columns
1885
+
1690
1886
  */
1691
1887
  select(columns: Record<string, ColumnDef | FunctionNode | CaseExpressionNode | WindowFunctionNode>): SelectQueryBuilder<T, TTable>;
1692
1888
  /**
1889
+
1693
1890
  * Selects raw column expressions
1891
+
1694
1892
  * @param cols - Column expressions as strings
1893
+
1695
1894
  * @returns New query builder instance with raw column selections
1895
+
1696
1896
  */
1697
1897
  selectRaw(...cols: string[]): SelectQueryBuilder<T, TTable>;
1698
1898
  /**
1899
+
1699
1900
  * Adds a Common Table Expression (CTE) to the query
1901
+
1700
1902
  * @param name - Name of the CTE
1903
+
1701
1904
  * @param query - Query builder or query node for the CTE
1905
+
1702
1906
  * @param columns - Optional column names for the CTE
1907
+
1703
1908
  * @returns New query builder instance with the CTE
1909
+
1704
1910
  */
1705
1911
  with(name: string, query: SelectQueryBuilder<any, TableDef<any>> | SelectQueryNode, columns?: string[]): SelectQueryBuilder<T, TTable>;
1706
1912
  /**
1913
+
1707
1914
  * Adds a recursive Common Table Expression (CTE) to the query
1915
+
1708
1916
  * @param name - Name of the CTE
1917
+
1709
1918
  * @param query - Query builder or query node for the CTE
1919
+
1710
1920
  * @param columns - Optional column names for the CTE
1921
+
1711
1922
  * @returns New query builder instance with the recursive CTE
1923
+
1712
1924
  */
1713
1925
  withRecursive(name: string, query: SelectQueryBuilder<any, TableDef<any>> | SelectQueryNode, columns?: string[]): SelectQueryBuilder<T, TTable>;
1714
1926
  /**
1927
+
1715
1928
  * Selects a subquery as a column
1929
+
1716
1930
  * @param alias - Alias for the subquery column
1931
+
1717
1932
  * @param sub - Query builder or query node for the subquery
1933
+
1718
1934
  * @returns New query builder instance with the subquery selection
1935
+
1719
1936
  */
1720
1937
  selectSubquery(alias: string, sub: SelectQueryBuilder<any, TableDef<any>> | SelectQueryNode): SelectQueryBuilder<T, TTable>;
1721
1938
  /**
1939
+
1722
1940
  * Adds an INNER JOIN to the query
1941
+
1723
1942
  * @param table - Table to join
1943
+
1724
1944
  * @param condition - Join condition expression
1945
+
1725
1946
  * @returns New query builder instance with the INNER JOIN
1947
+
1726
1948
  */
1727
1949
  innerJoin(table: TableDef, condition: BinaryExpressionNode): SelectQueryBuilder<T, TTable>;
1728
1950
  /**
1951
+
1729
1952
  * Adds a LEFT JOIN to the query
1953
+
1730
1954
  * @param table - Table to join
1955
+
1731
1956
  * @param condition - Join condition expression
1957
+
1732
1958
  * @returns New query builder instance with the LEFT JOIN
1959
+
1733
1960
  */
1734
1961
  leftJoin(table: TableDef, condition: BinaryExpressionNode): SelectQueryBuilder<T, TTable>;
1735
1962
  /**
1963
+
1736
1964
  * Adds a RIGHT JOIN to the query
1965
+
1737
1966
  * @param table - Table to join
1967
+
1738
1968
  * @param condition - Join condition expression
1969
+
1739
1970
  * @returns New query builder instance with the RIGHT JOIN
1971
+
1740
1972
  */
1741
1973
  rightJoin(table: TableDef, condition: BinaryExpressionNode): SelectQueryBuilder<T, TTable>;
1742
1974
  /**
1975
+
1743
1976
  * Matches records based on a relationship
1977
+
1744
1978
  * @param relationName - Name of the relationship to match
1979
+
1745
1980
  * @param predicate - Optional predicate expression
1981
+
1746
1982
  * @returns New query builder instance with the relationship match
1983
+
1747
1984
  */
1748
1985
  match(relationName: string, predicate?: ExpressionNode): SelectQueryBuilder<T, TTable>;
1749
1986
  /**
1987
+
1750
1988
  * Joins a related table
1989
+
1751
1990
  * @param relationName - Name of the relationship to join
1991
+
1752
1992
  * @param joinKind - Type of join (defaults to INNER)
1993
+
1753
1994
  * @param extraCondition - Optional additional join condition
1995
+
1754
1996
  * @returns New query builder instance with the relationship join
1997
+
1755
1998
  */
1756
1999
  joinRelation(relationName: string, joinKind?: JoinKind, extraCondition?: ExpressionNode): SelectQueryBuilder<T, TTable>;
1757
2000
  /**
2001
+
1758
2002
  * Includes related data in the query results
2003
+
1759
2004
  * @param relationName - Name of the relationship to include
2005
+
1760
2006
  * @param options - Optional include options
2007
+
1761
2008
  * @returns New query builder instance with the relationship inclusion
2009
+
1762
2010
  */
1763
2011
  include(relationName: string, options?: RelationIncludeOptions): SelectQueryBuilder<T, TTable>;
1764
2012
  includeLazy<K extends keyof RelationMap<TTable>>(relationName: K): SelectQueryBuilder<T, TTable>;
1765
2013
  getLazyRelations(): (keyof RelationMap<TTable>)[];
1766
2014
  getTable(): TTable;
1767
- execute(ctx: OrmContext): Promise<Entity<TTable>[]>;
2015
+ execute(ctx: OrmSession): Promise<Entity<TTable>[]>;
2016
+ executeWithContexts(execCtx: ExecutionContext, hydCtx: HydrationContext): Promise<Entity<TTable>[]>;
1768
2017
  /**
2018
+
1769
2019
  * Adds a WHERE condition to the query
2020
+
1770
2021
  * @param expr - Expression for the WHERE clause
2022
+
1771
2023
  * @returns New query builder instance with the WHERE condition
2024
+
1772
2025
  */
1773
2026
  where(expr: ExpressionNode): SelectQueryBuilder<T, TTable>;
1774
2027
  /**
2028
+
1775
2029
  * Adds a GROUP BY clause to the query
2030
+
1776
2031
  * @param col - Column definition or column node to group by
2032
+
1777
2033
  * @returns New query builder instance with the GROUP BY clause
2034
+
1778
2035
  */
1779
2036
  groupBy(col: ColumnDef | ColumnNode): SelectQueryBuilder<T, TTable>;
1780
2037
  /**
2038
+
1781
2039
  * Adds a HAVING condition to the query
2040
+
1782
2041
  * @param expr - Expression for the HAVING clause
2042
+
1783
2043
  * @returns New query builder instance with the HAVING condition
2044
+
1784
2045
  */
1785
2046
  having(expr: ExpressionNode): SelectQueryBuilder<T, TTable>;
1786
2047
  /**
2048
+
1787
2049
  * Adds an ORDER BY clause to the query
2050
+
1788
2051
  * @param col - Column definition or column node to order by
2052
+
1789
2053
  * @param direction - Order direction (defaults to ASC)
2054
+
1790
2055
  * @returns New query builder instance with the ORDER BY clause
2056
+
1791
2057
  */
1792
2058
  orderBy(col: ColumnDef | ColumnNode, direction?: OrderDirection): SelectQueryBuilder<T, TTable>;
1793
2059
  /**
2060
+
1794
2061
  * Adds a DISTINCT clause to the query
2062
+
1795
2063
  * @param cols - Columns to make distinct
2064
+
1796
2065
  * @returns New query builder instance with the DISTINCT clause
2066
+
1797
2067
  */
1798
2068
  distinct(...cols: (ColumnDef | ColumnNode)[]): SelectQueryBuilder<T, TTable>;
1799
2069
  /**
2070
+
1800
2071
  * Adds a LIMIT clause to the query
2072
+
1801
2073
  * @param n - Maximum number of rows to return
2074
+
1802
2075
  * @returns New query builder instance with the LIMIT clause
2076
+
1803
2077
  */
1804
2078
  limit(n: number): SelectQueryBuilder<T, TTable>;
1805
2079
  /**
2080
+
1806
2081
  * Adds an OFFSET clause to the query
2082
+
1807
2083
  * @param n - Number of rows to skip
2084
+
1808
2085
  * @returns New query builder instance with the OFFSET clause
2086
+
1809
2087
  */
1810
2088
  offset(n: number): SelectQueryBuilder<T, TTable>;
1811
2089
  /**
2090
+
1812
2091
  * Combines this query with another using UNION
2092
+
1813
2093
  * @param query - Query to union with
2094
+
1814
2095
  * @returns New query builder instance with the set operation
2096
+
1815
2097
  */
1816
2098
  union(query: SelectQueryBuilder<any, TableDef<any>> | SelectQueryNode): SelectQueryBuilder<T, TTable>;
1817
2099
  /**
2100
+
1818
2101
  * Combines this query with another using UNION ALL
2102
+
1819
2103
  * @param query - Query to union with
2104
+
1820
2105
  * @returns New query builder instance with the set operation
2106
+
1821
2107
  */
1822
2108
  unionAll(query: SelectQueryBuilder<any, TableDef<any>> | SelectQueryNode): SelectQueryBuilder<T, TTable>;
1823
2109
  /**
2110
+
1824
2111
  * Combines this query with another using INTERSECT
2112
+
1825
2113
  * @param query - Query to intersect with
2114
+
1826
2115
  * @returns New query builder instance with the set operation
2116
+
1827
2117
  */
1828
2118
  intersect(query: SelectQueryBuilder<any, TableDef<any>> | SelectQueryNode): SelectQueryBuilder<T, TTable>;
1829
2119
  /**
2120
+
1830
2121
  * Combines this query with another using EXCEPT
2122
+
1831
2123
  * @param query - Query to subtract
2124
+
1832
2125
  * @returns New query builder instance with the set operation
2126
+
1833
2127
  */
1834
2128
  except(query: SelectQueryBuilder<any, TableDef<any>> | SelectQueryNode): SelectQueryBuilder<T, TTable>;
1835
2129
  /**
2130
+
1836
2131
  * Adds a WHERE EXISTS condition to the query
2132
+
1837
2133
  * @param subquery - Subquery to check for existence
2134
+
1838
2135
  * @returns New query builder instance with the WHERE EXISTS condition
2136
+
1839
2137
  */
1840
2138
  whereExists(subquery: SelectQueryBuilder<any, TableDef<any>> | SelectQueryNode): SelectQueryBuilder<T, TTable>;
1841
2139
  /**
2140
+
1842
2141
  * Adds a WHERE NOT EXISTS condition to the query
2142
+
1843
2143
  * @param subquery - Subquery to check for non-existence
2144
+
1844
2145
  * @returns New query builder instance with the WHERE NOT EXISTS condition
2146
+
1845
2147
  */
1846
2148
  whereNotExists(subquery: SelectQueryBuilder<any, TableDef<any>> | SelectQueryNode): SelectQueryBuilder<T, TTable>;
1847
2149
  /**
2150
+
1848
2151
  * Adds a WHERE EXISTS condition based on a relationship
2152
+
1849
2153
  * @param relationName - Name of the relationship to check
2154
+
1850
2155
  * @param callback - Optional callback to modify the relationship query
2156
+
1851
2157
  * @returns New query builder instance with the relationship existence check
2158
+
1852
2159
  */
1853
2160
  whereHas(relationName: string, callback?: <TChildTable extends TableDef>(qb: SelectQueryBuilder<any, TChildTable>) => SelectQueryBuilder<any, TChildTable>): SelectQueryBuilder<T, TTable>;
1854
2161
  /**
2162
+
1855
2163
  * Adds a WHERE NOT EXISTS condition based on a relationship
2164
+
1856
2165
  * @param relationName - Name of the relationship to check
2166
+
1857
2167
  * @param callback - Optional callback to modify the relationship query
2168
+
1858
2169
  * @returns New query builder instance with the relationship non-existence check
2170
+
1859
2171
  */
1860
2172
  whereHasNot(relationName: string, callback?: <TChildTable extends TableDef>(qb: SelectQueryBuilder<any, TChildTable>) => SelectQueryBuilder<any, TChildTable>): SelectQueryBuilder<T, TTable>;
1861
2173
  /**
2174
+
1862
2175
  * Compiles the query to SQL for a specific dialect
2176
+
1863
2177
  * @param dialect - Database dialect to compile for
2178
+
1864
2179
  * @returns Compiled query with SQL and parameters
2180
+
1865
2181
  */
1866
2182
  compile(dialect: SelectDialectInput): CompiledQuery;
1867
2183
  /**
2184
+
1868
2185
  * Converts the query to SQL string for a specific dialect
2186
+
1869
2187
  * @param dialect - Database dialect to generate SQL for
2188
+
1870
2189
  * @returns SQL string representation of the query
2190
+
1871
2191
  */
1872
2192
  toSql(dialect: SelectDialectInput): string;
1873
2193
  /**
2194
+
1874
2195
  * Gets the hydration plan for the query
2196
+
1875
2197
  * @returns Hydration plan or undefined if none exists
2198
+
1876
2199
  */
1877
2200
  getHydrationPlan(): HydrationPlan | undefined;
1878
2201
  /**
2202
+
1879
2203
  * Gets the Abstract Syntax Tree (AST) representation of the query
2204
+
1880
2205
  * @returns Query AST with hydration applied
2206
+
1881
2207
  */
1882
2208
  getAST(): SelectQueryNode;
1883
2209
  }
1884
2210
  /**
2211
+
1885
2212
  * Creates a column node for use in expressions
2213
+
1886
2214
  * @param table - Table name
2215
+
1887
2216
  * @param name - Column name
2217
+
1888
2218
  * @returns ColumnNode with the specified table and name
2219
+
1889
2220
  */
1890
2221
  declare const createColumn: (table: string, name: string) => ColumnNode;
1891
2222
  /**
2223
+
1892
2224
  * Creates a literal value node for use in expressions
2225
+
1893
2226
  * @param val - Literal value (string or number)
2227
+
1894
2228
  * @returns LiteralNode with the specified value
2229
+
1895
2230
  */
1896
2231
  declare const createLiteral: (val: string | number) => LiteralNode;
1897
2232
 
1898
- export { type RawDefaultValue as $, type BelongsToManyRelation as A, type BinaryExpressionNode as B, type ColumnRef as C, Dialect as D, type ExpressionNode as E, type FunctionNode as F, type HasManyCollection as G, type HydrationPlan as H, type InExpressionNode as I, type JsonPathNode as J, type BelongsToReference as K, type LogicalExpressionNode as L, type ManyToManyCollection as M, type NullExpressionNode as N, type OperandNode as O, SelectQueryBuilder as P, type CheckConstraint as Q, type RelationMap as R, type SelectQueryNode as S, type TableRef as T, type UpdateQueryNode as U, type TableOptions as V, type WindowFunctionNode as W, type TableHooks as X, defineTable as Y, type ColumnType as Z, type ReferentialAction as _, type ColumnNode as a, type DefaultValue as a0, col as a1, RelationKinds as a2, type RelationType as a3, type CascadeMode as a4, type RelationDef as a5, hasMany as a6, hasOne as a7, belongsTo as a8, belongsToMany as a9, createExecutorFromQueryRunner as aA, type ColumnToTs as aa, type InferRow as ab, type HasOneReference as ac, createColumn as ad, createLiteral as ae, isOperandNode as af, isFunctionNode as ag, isCaseExpressionNode as ah, isWindowFunctionNode as ai, isExpressionSelectionNode as aj, type HydrationPivotPlan as ak, type HydrationRelationPlan as al, type HydrationMetadata as am, addDomainEvent as an, EntityStatus as ao, type QueryResult as ap, type RelationKey as aq, type RelationChange as ar, type HasDomainEvents as as, type OrmInterceptor as at, type DomainEventHandler as au, type OrmContextOptions as av, type QueryLogEntry as aw, type QueryLogger as ax, rowsToQueryResult as ay, type SimpleQueryRunner as az, type LiteralNode as b, type BetweenExpressionNode as c, type CaseExpressionNode as d, type ExistsExpressionNode as e, type OrderDirection as f, type ScalarSubqueryNode as g, type ColumnDef as h, type TableDef as i, type InsertQueryNode as j, type InsertCompiler as k, type CompiledQuery as l, type DialectKey as m, type UpdateCompiler as n, type DeleteQueryNode as o, type DeleteCompiler as p, type CompilerContext as q, type ForeignKeyReference as r, type IndexColumn as s, type IndexDef as t, type DbExecutor as u, OrmContext as v, type Entity as w, type HasManyRelation as x, type HasOneRelation as y, type BelongsToRelation as z };
2233
+ export { type TableHooks as $, type BelongsToRelation as A, type BinaryExpressionNode as B, type ColumnRef as C, Dialect as D, type ExpressionNode as E, type FunctionNode as F, type BelongsToManyRelation as G, type HydrationPlan as H, type InExpressionNode as I, type JsonPathNode as J, type HasManyCollection as K, type LogicalExpressionNode as L, type BelongsToReference as M, type NullExpressionNode as N, type OperandNode as O, type ManyToManyCollection as P, OrmSession as Q, type RelationMap as R, type SelectQueryNode as S, type TableRef as T, type UpdateQueryNode as U, SelectQueryBuilder as V, type WindowFunctionNode as W, type ExecutionContext as X, type HydrationContext as Y, type CheckConstraint as Z, type TableOptions as _, type ColumnNode as a, defineTable as a0, type ColumnType as a1, type ReferentialAction as a2, type RawDefaultValue as a3, type DefaultValue as a4, col as a5, RelationKinds as a6, type RelationType as a7, type CascadeMode as a8, type RelationDef as a9, EntityStatus as aA, type TrackedEntity as aB, type RelationKey as aC, type RelationChange as aD, type RelationChangeEntry as aE, type HasDomainEvents as aF, type QueryLogEntry as aG, type QueryLogger as aH, createQueryLoggingExecutor as aI, type QueryResult as aJ, rowsToQueryResult as aK, type SimpleQueryRunner as aL, createExecutorFromQueryRunner as aM, type EntityOrTableTargetResolver as aN, type EntityConstructor as aO, hasMany as aa, hasOne as ab, belongsTo as ac, belongsToMany as ad, type ColumnToTs as ae, type InferRow as af, type HasOneReference as ag, createColumn as ah, createLiteral as ai, isOperandNode as aj, isFunctionNode as ak, isCaseExpressionNode as al, isWindowFunctionNode as am, isExpressionSelectionNode as an, type HydrationPivotPlan as ao, type HydrationRelationPlan as ap, type HydrationMetadata as aq, type OrmInterceptor as ar, type OrmSessionOptions as as, type OrmOptions as at, type DbExecutorFactory as au, type ExternalTransaction as av, Orm as aw, type DomainEventHandler as ax, DomainEventBus as ay, addDomainEvent as az, type LiteralNode as b, type BetweenExpressionNode as c, type CaseExpressionNode as d, type ExistsExpressionNode as e, type OrderDirection as f, type ScalarSubqueryNode as g, type ColumnDef as h, type TableDef as i, type InsertQueryNode as j, type InsertCompiler as k, type CompiledQuery as l, type DialectKey as m, type UpdateCompiler as n, type DeleteQueryNode as o, type DeleteCompiler as p, type CompilerContext as q, type ForeignKeyReference as r, type IndexColumn as s, type IndexDef as t, type DbExecutor as u, type NamingStrategy as v, type EntityContext as w, type Entity as x, type HasManyRelation as y, type HasOneRelation as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "metal-orm",
3
- "version": "1.0.15",
3
+ "version": "1.0.16",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {