metal-orm 1.0.59 → 1.0.60

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.
package/dist/index.js CHANGED
@@ -6428,6 +6428,8 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
6428
6428
  /**
6429
6429
  * Applies an alias to the root FROM table.
6430
6430
  * @param alias - Alias to apply
6431
+ * @example
6432
+ * const qb = new SelectQueryBuilder(userTable).as('u');
6431
6433
  */
6432
6434
  as(alias) {
6433
6435
  const nextContext = this.fromFacet.as(this.context, alias);
@@ -6485,6 +6487,8 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
6485
6487
  * Selects raw column expressions
6486
6488
  * @param cols - Column expressions as strings
6487
6489
  * @returns New query builder instance with raw column selections
6490
+ * @example
6491
+ * qb.selectRaw('COUNT(*) as total', 'UPPER(name) as upper_name');
6488
6492
  */
6489
6493
  selectRaw(...cols) {
6490
6494
  return this.clone(this.projectionFacet.selectRaw(this.context, cols));
@@ -6495,6 +6499,12 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
6495
6499
  * @param query - Query builder or query node for the CTE
6496
6500
  * @param columns - Optional column names for the CTE
6497
6501
  * @returns New query builder instance with the CTE
6502
+ * @example
6503
+ * const recentUsers = new SelectQueryBuilder(userTable)
6504
+ * .where(gt(userTable.columns.createdAt, subDays(now(), 30)));
6505
+ * const qb = new SelectQueryBuilder(userTable)
6506
+ * .with('recent_users', recentUsers)
6507
+ * .from('recent_users');
6498
6508
  */
6499
6509
  with(name, query, columns) {
6500
6510
  const subAst = resolveSelectQuery(query);
@@ -6507,6 +6517,19 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
6507
6517
  * @param query - Query builder or query node for the CTE
6508
6518
  * @param columns - Optional column names for the CTE
6509
6519
  * @returns New query builder instance with the recursive CTE
6520
+ * @example
6521
+ * // Base case: select root nodes
6522
+ * const baseQuery = new SelectQueryBuilder(orgTable)
6523
+ * .where(eq(orgTable.columns.parentId, 1));
6524
+ * // Recursive case: join with the CTE itself
6525
+ * const recursiveQuery = new SelectQueryBuilder(orgTable)
6526
+ * .join('org_hierarchy', 'oh', eq(orgTable.columns.parentId, col('oh.id')));
6527
+ * // Combine base and recursive parts
6528
+ * const orgHierarchy = baseQuery.union(recursiveQuery);
6529
+ * // Use in main query
6530
+ * const qb = new SelectQueryBuilder(orgTable)
6531
+ * .withRecursive('org_hierarchy', orgHierarchy)
6532
+ * .from('org_hierarchy');
6510
6533
  */
6511
6534
  withRecursive(name, query, columns) {
6512
6535
  const subAst = resolveSelectQuery(query);
@@ -6519,6 +6542,11 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
6519
6542
  * @param alias - Alias for the derived table
6520
6543
  * @param columnAliases - Optional column alias list
6521
6544
  * @returns New query builder instance with updated FROM
6545
+ * @example
6546
+ * const subquery = new SelectQueryBuilder(userTable)
6547
+ * .select('id', 'name')
6548
+ * .where(gt(userTable.columns.score, 100));
6549
+ * qb.fromSubquery(subquery, 'high_scorers', ['userId', 'userName']);
6522
6550
  */
6523
6551
  fromSubquery(subquery, alias, columnAliases) {
6524
6552
  const subAst = resolveSelectQuery(subquery);
@@ -6531,6 +6559,13 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
6531
6559
  * @param args - Optional function arguments
6532
6560
  * @param alias - Optional alias for the function table
6533
6561
  * @param options - Optional function-table metadata (lateral, ordinality, column aliases, schema)
6562
+ * @example
6563
+ * qb.fromFunctionTable(
6564
+ * 'generate_series',
6565
+ * [literal(1), literal(10), literal(1)],
6566
+ * 'series',
6567
+ * { columnAliases: ['value'] }
6568
+ * );
6534
6569
  */
6535
6570
  fromFunctionTable(name, args = [], alias, options) {
6536
6571
  const nextContext = this.fromFacet.fromFunctionTable(this.context, name, args, alias, options);
@@ -6541,6 +6576,12 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
6541
6576
  * @param alias - Alias for the subquery column
6542
6577
  * @param sub - Query builder or query node for the subquery
6543
6578
  * @returns New query builder instance with the subquery selection
6579
+ * @example
6580
+ * const postCount = new SelectQueryBuilder(postTable)
6581
+ * .select(count(postTable.columns.id))
6582
+ * .where(eq(postTable.columns.userId, col('u.id')));
6583
+ * qb.select('id', 'name')
6584
+ * .selectSubquery('postCount', postCount);
6544
6585
  */
6545
6586
  selectSubquery(alias, sub2) {
6546
6587
  const query = resolveSelectQuery(sub2);
@@ -6554,6 +6595,15 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
6554
6595
  * @param joinKind - Join kind (defaults to INNER)
6555
6596
  * @param columnAliases - Optional column alias list for the derived table
6556
6597
  * @returns New query builder instance with the derived-table join
6598
+ * @example
6599
+ * const activeUsers = new SelectQueryBuilder(userTable)
6600
+ * .where(eq(userTable.columns.active, true));
6601
+ * qb.joinSubquery(
6602
+ * activeUsers,
6603
+ * 'au',
6604
+ * eq(col('t.userId'), col('au.id')),
6605
+ * JOIN_KINDS.LEFT
6606
+ * );
6557
6607
  */
6558
6608
  joinSubquery(subquery, alias, condition, joinKind = JOIN_KINDS.INNER, columnAliases) {
6559
6609
  const subAst = resolveSelectQuery(subquery);
@@ -6568,6 +6618,15 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
6568
6618
  * @param condition - Join condition expression
6569
6619
  * @param joinKind - Kind of join (defaults to INNER)
6570
6620
  * @param options - Optional metadata (lateral, ordinality, column aliases, schema)
6621
+ * @example
6622
+ * qb.joinFunctionTable(
6623
+ * 'generate_series',
6624
+ * [literal(1), literal(10)],
6625
+ * 'gs',
6626
+ * eq(col('t.value'), col('gs.value')),
6627
+ * JOIN_KINDS.INNER,
6628
+ * { columnAliases: ['value'] }
6629
+ * );
6571
6630
  */
6572
6631
  joinFunctionTable(name, args = [], alias, condition, joinKind = JOIN_KINDS.INNER, options) {
6573
6632
  const nextContext = this.joinFacet.joinFunctionTable(this.context, name, args, alias, condition, joinKind, options);
@@ -6578,6 +6637,11 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
6578
6637
  * @param table - Table to join
6579
6638
  * @param condition - Join condition expression
6580
6639
  * @returns New query builder instance with the INNER JOIN
6640
+ * @example
6641
+ * qb.innerJoin(
6642
+ * postTable,
6643
+ * eq(userTable.columns.id, postTable.columns.userId)
6644
+ * );
6581
6645
  */
6582
6646
  innerJoin(table, condition) {
6583
6647
  const nextContext = this.joinFacet.applyJoin(this.context, table, condition, JOIN_KINDS.INNER);
@@ -6588,6 +6652,11 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
6588
6652
  * @param table - Table to join
6589
6653
  * @param condition - Join condition expression
6590
6654
  * @returns New query builder instance with the LEFT JOIN
6655
+ * @example
6656
+ * qb.leftJoin(
6657
+ * postTable,
6658
+ * eq(userTable.columns.id, postTable.columns.userId)
6659
+ * );
6591
6660
  */
6592
6661
  leftJoin(table, condition) {
6593
6662
  const nextContext = this.joinFacet.applyJoin(this.context, table, condition, JOIN_KINDS.LEFT);
@@ -6598,6 +6667,11 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
6598
6667
  * @param table - Table to join
6599
6668
  * @param condition - Join condition expression
6600
6669
  * @returns New query builder instance with the RIGHT JOIN
6670
+ * @example
6671
+ * qb.rightJoin(
6672
+ * postTable,
6673
+ * eq(userTable.columns.id, postTable.columns.userId)
6674
+ * );
6601
6675
  */
6602
6676
  rightJoin(table, condition) {
6603
6677
  const nextContext = this.joinFacet.applyJoin(this.context, table, condition, JOIN_KINDS.RIGHT);
@@ -6608,6 +6682,8 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
6608
6682
  * @param relationName - Name of the relationship to match
6609
6683
  * @param predicate - Optional predicate expression
6610
6684
  * @returns New query builder instance with the relationship match
6685
+ * @example
6686
+ * qb.match('posts', eq(postTable.columns.published, true));
6611
6687
  */
6612
6688
  match(relationName, predicate) {
6613
6689
  const nextContext = this.relationFacet.match(this.context, relationName, predicate);
@@ -6619,6 +6695,10 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
6619
6695
  * @param joinKind - Type of join (defaults to INNER)
6620
6696
  * @param extraCondition - Optional additional join condition
6621
6697
  * @returns New query builder instance with the relationship join
6698
+ * @example
6699
+ * qb.joinRelation('posts', JOIN_KINDS.LEFT);
6700
+ * @example
6701
+ * qb.joinRelation('posts', JOIN_KINDS.INNER, eq(postTable.columns.published, true));
6622
6702
  */
6623
6703
  joinRelation(relationName, joinKind = JOIN_KINDS.INNER, extraCondition) {
6624
6704
  const nextContext = this.relationFacet.joinRelation(this.context, relationName, joinKind, extraCondition);
@@ -6629,6 +6709,15 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
6629
6709
  * @param relationName - Name of the relationship to include
6630
6710
  * @param options - Optional include options
6631
6711
  * @returns New query builder instance with the relationship inclusion
6712
+ * @example
6713
+ * qb.include('posts');
6714
+ * @example
6715
+ * qb.include('posts', { columns: ['id', 'title', 'published'] });
6716
+ * @example
6717
+ * qb.include('posts', {
6718
+ * columns: ['id', 'title'],
6719
+ * where: eq(postTable.columns.published, true)
6720
+ * });
6632
6721
  */
6633
6722
  include(relationName, options) {
6634
6723
  const nextContext = this.relationFacet.include(this.context, relationName, options);
@@ -6639,6 +6728,11 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
6639
6728
  * @param relationName - Name of the relation to include lazily
6640
6729
  * @param options - Optional include options for lazy loading
6641
6730
  * @returns New query builder instance with lazy relation inclusion
6731
+ * @example
6732
+ * const qb = new SelectQueryBuilder(userTable).includeLazy('posts');
6733
+ * const users = await qb.execute(session);
6734
+ * // Access posts later - they will be loaded on demand
6735
+ * const posts = await users[0].posts;
6642
6736
  */
6643
6737
  includeLazy(relationName, options) {
6644
6738
  let nextContext = this.context;
@@ -6668,6 +6762,8 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
6668
6762
  }
6669
6763
  /**
6670
6764
  * Convenience alias for including only specific columns from a relation.
6765
+ * @example
6766
+ * qb.includePick('posts', ['id', 'title', 'createdAt']);
6671
6767
  */
6672
6768
  includePick(relationName, cols) {
6673
6769
  const options = { columns: cols };
@@ -6677,6 +6773,11 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
6677
6773
  * Selects columns for the root table and relations from an array of entries
6678
6774
  * @param config - Configuration array for deep column selection
6679
6775
  * @returns New query builder instance with deep column selections
6776
+ * @example
6777
+ * qb.selectColumnsDeep([
6778
+ * { type: 'root', columns: ['id', 'name'] },
6779
+ * { type: 'relation', relationName: 'posts', columns: ['id', 'title'] }
6780
+ * ]);
6680
6781
  */
6681
6782
  selectColumnsDeep(config) {
6682
6783
  let currBuilder = this;
@@ -6715,6 +6816,10 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
6715
6816
  * Executes the query and returns hydrated results
6716
6817
  * @param ctx - ORM session context
6717
6818
  * @returns Promise of entity instances
6819
+ * @example
6820
+ * const users = await qb.select('id', 'name')
6821
+ * .where(eq(userTable.columns.active, true))
6822
+ * .execute(session);
6718
6823
  */
6719
6824
  async execute(ctx) {
6720
6825
  return executeHydrated(ctx, this);
@@ -6742,6 +6847,10 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
6742
6847
  * @param execCtx - Execution context
6743
6848
  * @param hydCtx - Hydration context
6744
6849
  * @returns Promise of entity instances
6850
+ * @example
6851
+ * const execCtx = new ExecutionContext(session);
6852
+ * const hydCtx = new HydrationContext();
6853
+ * const users = await qb.executeWithContexts(execCtx, hydCtx);
6745
6854
  */
6746
6855
  async executeWithContexts(execCtx, hydCtx) {
6747
6856
  return executeHydratedWithContexts(execCtx, hydCtx, this);
@@ -6750,6 +6859,13 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
6750
6859
  * Adds a WHERE condition to the query
6751
6860
  * @param expr - Expression for the WHERE clause
6752
6861
  * @returns New query builder instance with the WHERE condition
6862
+ * @example
6863
+ * qb.where(eq(userTable.columns.id, 1));
6864
+ * @example
6865
+ * qb.where(and(
6866
+ * eq(userTable.columns.active, true),
6867
+ * gt(userTable.columns.createdAt, subDays(now(), 30))
6868
+ * ));
6753
6869
  */
6754
6870
  where(expr) {
6755
6871
  const nextContext = this.predicateFacet.where(this.context, expr);
@@ -6759,6 +6875,9 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
6759
6875
  * Adds a GROUP BY clause to the query
6760
6876
  * @param term - Column definition or ordering term to group by
6761
6877
  * @returns New query builder instance with the GROUP BY clause
6878
+ * @example
6879
+ * qb.select('departmentId', count(userTable.columns.id))
6880
+ * .groupBy(userTable.columns.departmentId);
6762
6881
  */
6763
6882
  groupBy(term) {
6764
6883
  const nextContext = this.predicateFacet.groupBy(this.context, term);
@@ -6768,6 +6887,10 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
6768
6887
  * Adds a HAVING condition to the query
6769
6888
  * @param expr - Expression for the HAVING clause
6770
6889
  * @returns New query builder instance with the HAVING condition
6890
+ * @example
6891
+ * qb.select('departmentId', count(userTable.columns.id))
6892
+ * .groupBy(userTable.columns.departmentId)
6893
+ * .having(gt(count(userTable.columns.id), 5));
6771
6894
  */
6772
6895
  having(expr) {
6773
6896
  const nextContext = this.predicateFacet.having(this.context, expr);
@@ -6790,6 +6913,10 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
6790
6913
  * Adds a DISTINCT clause to the query
6791
6914
  * @param cols - Columns to make distinct
6792
6915
  * @returns New query builder instance with the DISTINCT clause
6916
+ * @example
6917
+ * qb.distinct(userTable.columns.email);
6918
+ * @example
6919
+ * qb.distinct(userTable.columns.firstName, userTable.columns.lastName);
6793
6920
  */
6794
6921
  distinct(...cols) {
6795
6922
  return this.clone(this.projectionFacet.distinct(this.context, cols));
@@ -6798,6 +6925,10 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
6798
6925
  * Adds a LIMIT clause to the query
6799
6926
  * @param n - Maximum number of rows to return
6800
6927
  * @returns New query builder instance with the LIMIT clause
6928
+ * @example
6929
+ * qb.limit(10);
6930
+ * @example
6931
+ * qb.limit(20).offset(40); // Pagination: page 3 with 20 items per page
6801
6932
  */
6802
6933
  limit(n) {
6803
6934
  const nextContext = this.predicateFacet.limit(this.context, n);
@@ -6807,6 +6938,10 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
6807
6938
  * Adds an OFFSET clause to the query
6808
6939
  * @param n - Number of rows to skip
6809
6940
  * @returns New query builder instance with the OFFSET clause
6941
+ * @example
6942
+ * qb.offset(10);
6943
+ * @example
6944
+ * qb.limit(20).offset(40); // Pagination: page 3 with 20 items per page
6810
6945
  */
6811
6946
  offset(n) {
6812
6947
  const nextContext = this.predicateFacet.offset(this.context, n);
@@ -6816,6 +6951,12 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
6816
6951
  * Combines this query with another using UNION
6817
6952
  * @param query - Query to union with
6818
6953
  * @returns New query builder instance with the set operation
6954
+ * @example
6955
+ * const activeUsers = new SelectQueryBuilder(userTable)
6956
+ * .where(eq(userTable.columns.active, true));
6957
+ * const inactiveUsers = new SelectQueryBuilder(userTable)
6958
+ * .where(eq(userTable.columns.active, false));
6959
+ * qb.union(activeUsers).union(inactiveUsers);
6819
6960
  */
6820
6961
  union(query) {
6821
6962
  return this.clone(this.applySetOperation("UNION", query));
@@ -6824,6 +6965,10 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
6824
6965
  * Combines this query with another using UNION ALL
6825
6966
  * @param query - Query to union with
6826
6967
  * @returns New query builder instance with the set operation
6968
+ * @example
6969
+ * const q1 = new SelectQueryBuilder(userTable).where(gt(userTable.columns.score, 80));
6970
+ * const q2 = new SelectQueryBuilder(userTable).where(lt(userTable.columns.score, 20));
6971
+ * qb.unionAll(q1).unionAll(q2);
6827
6972
  */
6828
6973
  unionAll(query) {
6829
6974
  return this.clone(this.applySetOperation("UNION ALL", query));
@@ -6832,6 +6977,12 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
6832
6977
  * Combines this query with another using INTERSECT
6833
6978
  * @param query - Query to intersect with
6834
6979
  * @returns New query builder instance with the set operation
6980
+ * @example
6981
+ * const activeUsers = new SelectQueryBuilder(userTable)
6982
+ * .where(eq(userTable.columns.active, true));
6983
+ * const premiumUsers = new SelectQueryBuilder(userTable)
6984
+ * .where(eq(userTable.columns.premium, true));
6985
+ * qb.intersect(activeUsers).intersect(premiumUsers);
6835
6986
  */
6836
6987
  intersect(query) {
6837
6988
  return this.clone(this.applySetOperation("INTERSECT", query));
@@ -6840,6 +6991,11 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
6840
6991
  * Combines this query with another using EXCEPT
6841
6992
  * @param query - Query to subtract
6842
6993
  * @returns New query builder instance with the set operation
6994
+ * @example
6995
+ * const allUsers = new SelectQueryBuilder(userTable);
6996
+ * const inactiveUsers = new SelectQueryBuilder(userTable)
6997
+ * .where(eq(userTable.columns.active, false));
6998
+ * qb.except(allUsers).except(inactiveUsers); // Only active users
6843
6999
  */
6844
7000
  except(query) {
6845
7001
  return this.clone(this.applySetOperation("EXCEPT", query));
@@ -6848,6 +7004,10 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
6848
7004
  * Adds a WHERE EXISTS condition to the query
6849
7005
  * @param subquery - Subquery to check for existence
6850
7006
  * @returns New query builder instance with the WHERE EXISTS condition
7007
+ * @example
7008
+ * const postsQuery = new SelectQueryBuilder(postTable)
7009
+ * .where(eq(postTable.columns.userId, col('u.id')));
7010
+ * qb.whereExists(postsQuery);
6851
7011
  */
6852
7012
  whereExists(subquery, correlate) {
6853
7013
  const subAst = resolveSelectQuery(subquery);
@@ -6858,6 +7018,10 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
6858
7018
  * Adds a WHERE NOT EXISTS condition to the query
6859
7019
  * @param subquery - Subquery to check for non-existence
6860
7020
  * @returns New query builder instance with the WHERE NOT EXISTS condition
7021
+ * @example
7022
+ * const postsQuery = new SelectQueryBuilder(postTable)
7023
+ * .where(eq(postTable.columns.userId, col('u.id')));
7024
+ * qb.whereNotExists(postsQuery); // Users without posts
6861
7025
  */
6862
7026
  whereNotExists(subquery, correlate) {
6863
7027
  const subAst = resolveSelectQuery(subquery);
@@ -6912,6 +7076,11 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
6912
7076
  * Compiles the query to SQL for a specific dialect
6913
7077
  * @param dialect - Database dialect to compile for
6914
7078
  * @returns Compiled query with SQL and parameters
7079
+ * @example
7080
+ * const compiled = qb.select('id', 'name')
7081
+ * .where(eq(userTable.columns.active, true))
7082
+ * .compile('postgres');
7083
+ * console.log(compiled.sql); // SELECT "id", "name" FROM "users" WHERE "active" = true
6915
7084
  */
6916
7085
  compile(dialect) {
6917
7086
  const resolved = resolveDialectInput(dialect);
@@ -6921,6 +7090,11 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
6921
7090
  * Converts the query to SQL string for a specific dialect
6922
7091
  * @param dialect - Database dialect to generate SQL for
6923
7092
  * @returns SQL string representation of the query
7093
+ * @example
7094
+ * const sql = qb.select('id', 'name')
7095
+ * .where(eq(userTable.columns.active, true))
7096
+ * .toSql('postgres');
7097
+ * console.log(sql); // SELECT "id", "name" FROM "users" WHERE "active" = true
6924
7098
  */
6925
7099
  toSql(dialect) {
6926
7100
  return this.compile(dialect).sql;
@@ -6928,6 +7102,9 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
6928
7102
  /**
6929
7103
  * Gets the hydration plan for the query
6930
7104
  * @returns Hydration plan or undefined if none exists
7105
+ * @example
7106
+ * const plan = qb.include('posts').getHydrationPlan();
7107
+ * console.log(plan?.relations); // Information about included relations
6931
7108
  */
6932
7109
  getHydrationPlan() {
6933
7110
  return this.context.hydration.getPlan();
@@ -6935,6 +7112,10 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
6935
7112
  /**
6936
7113
  * Gets the Abstract Syntax Tree (AST) representation of the query
6937
7114
  * @returns Query AST with hydration applied
7115
+ * @example
7116
+ * const ast = qb.select('id', 'name').getAST();
7117
+ * console.log(ast.columns); // Array of column nodes
7118
+ * console.log(ast.from); // From clause information
6938
7119
  */
6939
7120
  getAST() {
6940
7121
  return this.context.hydration.applyToAst(this.context.state.ast);
@@ -7821,6 +8002,39 @@ var DeleteQueryBuilder = class _DeleteQueryBuilder {
7821
8002
  };
7822
8003
  var isTableSourceNode2 = (source) => typeof source.type === "string";
7823
8004
 
8005
+ // src/query/target.ts
8006
+ var resolveEntityTarget = (ctor) => {
8007
+ const table = getTableDefFromEntity(ctor);
8008
+ if (!table) {
8009
+ throw new Error(`Entity '${ctor.name}' is not registered with decorators`);
8010
+ }
8011
+ return table;
8012
+ };
8013
+ var resolveTable = (target) => {
8014
+ if (isTableDef(target)) {
8015
+ return target;
8016
+ }
8017
+ return resolveEntityTarget(target);
8018
+ };
8019
+
8020
+ // src/query/index.ts
8021
+ var selectFrom = (target) => {
8022
+ const table = resolveTable(target);
8023
+ return new SelectQueryBuilder(table);
8024
+ };
8025
+ var insertInto = (target) => {
8026
+ const table = resolveTable(target);
8027
+ return new InsertQueryBuilder(table);
8028
+ };
8029
+ var update = (target) => {
8030
+ const table = resolveTable(target);
8031
+ return new UpdateQueryBuilder(table);
8032
+ };
8033
+ var deleteFrom = (target) => {
8034
+ const table = resolveTable(target);
8035
+ return new DeleteQueryBuilder(table);
8036
+ };
8037
+
7824
8038
  // src/core/ddl/sql-writing.ts
7825
8039
  var resolvePrimaryKey = (table) => {
7826
8040
  if (Array.isArray(table.primaryKey) && table.primaryKey.length > 0) {
@@ -12438,6 +12652,7 @@ export {
12438
12652
  dayOfWeek,
12439
12653
  defineTable,
12440
12654
  degrees,
12655
+ deleteFrom,
12441
12656
  denseRank,
12442
12657
  diffSchema,
12443
12658
  div,
@@ -12474,6 +12689,7 @@ export {
12474
12689
  inList,
12475
12690
  inSubquery,
12476
12691
  initcap,
12692
+ insertInto,
12477
12693
  instr,
12478
12694
  introspectSchema,
12479
12695
  isCaseExpressionNode,
@@ -12562,6 +12778,7 @@ export {
12562
12778
  rtrim,
12563
12779
  second,
12564
12780
  sel,
12781
+ selectFrom,
12565
12782
  selectFromEntity,
12566
12783
  setRelations,
12567
12784
  sha1,
@@ -12585,6 +12802,7 @@ export {
12585
12802
  trunc,
12586
12803
  truncate,
12587
12804
  unixTimestamp,
12805
+ update,
12588
12806
  upper,
12589
12807
  utcNow,
12590
12808
  valueToOperand,