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.cjs CHANGED
@@ -134,6 +134,7 @@ __export(index_exports, {
134
134
  dayOfWeek: () => dayOfWeek,
135
135
  defineTable: () => defineTable,
136
136
  degrees: () => degrees,
137
+ deleteFrom: () => deleteFrom,
137
138
  denseRank: () => denseRank,
138
139
  diffSchema: () => diffSchema,
139
140
  div: () => div,
@@ -170,6 +171,7 @@ __export(index_exports, {
170
171
  inList: () => inList,
171
172
  inSubquery: () => inSubquery,
172
173
  initcap: () => initcap,
174
+ insertInto: () => insertInto,
173
175
  instr: () => instr,
174
176
  introspectSchema: () => introspectSchema,
175
177
  isCaseExpressionNode: () => isCaseExpressionNode,
@@ -258,6 +260,7 @@ __export(index_exports, {
258
260
  rtrim: () => rtrim,
259
261
  second: () => second,
260
262
  sel: () => sel,
263
+ selectFrom: () => selectFrom,
261
264
  selectFromEntity: () => selectFromEntity,
262
265
  setRelations: () => setRelations,
263
266
  sha1: () => sha1,
@@ -281,6 +284,7 @@ __export(index_exports, {
281
284
  trunc: () => trunc,
282
285
  truncate: () => truncate,
283
286
  unixTimestamp: () => unixTimestamp,
287
+ update: () => update,
284
288
  upper: () => upper,
285
289
  utcNow: () => utcNow,
286
290
  valueToOperand: () => valueToOperand,
@@ -6692,6 +6696,8 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
6692
6696
  /**
6693
6697
  * Applies an alias to the root FROM table.
6694
6698
  * @param alias - Alias to apply
6699
+ * @example
6700
+ * const qb = new SelectQueryBuilder(userTable).as('u');
6695
6701
  */
6696
6702
  as(alias) {
6697
6703
  const nextContext = this.fromFacet.as(this.context, alias);
@@ -6749,6 +6755,8 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
6749
6755
  * Selects raw column expressions
6750
6756
  * @param cols - Column expressions as strings
6751
6757
  * @returns New query builder instance with raw column selections
6758
+ * @example
6759
+ * qb.selectRaw('COUNT(*) as total', 'UPPER(name) as upper_name');
6752
6760
  */
6753
6761
  selectRaw(...cols) {
6754
6762
  return this.clone(this.projectionFacet.selectRaw(this.context, cols));
@@ -6759,6 +6767,12 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
6759
6767
  * @param query - Query builder or query node for the CTE
6760
6768
  * @param columns - Optional column names for the CTE
6761
6769
  * @returns New query builder instance with the CTE
6770
+ * @example
6771
+ * const recentUsers = new SelectQueryBuilder(userTable)
6772
+ * .where(gt(userTable.columns.createdAt, subDays(now(), 30)));
6773
+ * const qb = new SelectQueryBuilder(userTable)
6774
+ * .with('recent_users', recentUsers)
6775
+ * .from('recent_users');
6762
6776
  */
6763
6777
  with(name, query, columns) {
6764
6778
  const subAst = resolveSelectQuery(query);
@@ -6771,6 +6785,19 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
6771
6785
  * @param query - Query builder or query node for the CTE
6772
6786
  * @param columns - Optional column names for the CTE
6773
6787
  * @returns New query builder instance with the recursive CTE
6788
+ * @example
6789
+ * // Base case: select root nodes
6790
+ * const baseQuery = new SelectQueryBuilder(orgTable)
6791
+ * .where(eq(orgTable.columns.parentId, 1));
6792
+ * // Recursive case: join with the CTE itself
6793
+ * const recursiveQuery = new SelectQueryBuilder(orgTable)
6794
+ * .join('org_hierarchy', 'oh', eq(orgTable.columns.parentId, col('oh.id')));
6795
+ * // Combine base and recursive parts
6796
+ * const orgHierarchy = baseQuery.union(recursiveQuery);
6797
+ * // Use in main query
6798
+ * const qb = new SelectQueryBuilder(orgTable)
6799
+ * .withRecursive('org_hierarchy', orgHierarchy)
6800
+ * .from('org_hierarchy');
6774
6801
  */
6775
6802
  withRecursive(name, query, columns) {
6776
6803
  const subAst = resolveSelectQuery(query);
@@ -6783,6 +6810,11 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
6783
6810
  * @param alias - Alias for the derived table
6784
6811
  * @param columnAliases - Optional column alias list
6785
6812
  * @returns New query builder instance with updated FROM
6813
+ * @example
6814
+ * const subquery = new SelectQueryBuilder(userTable)
6815
+ * .select('id', 'name')
6816
+ * .where(gt(userTable.columns.score, 100));
6817
+ * qb.fromSubquery(subquery, 'high_scorers', ['userId', 'userName']);
6786
6818
  */
6787
6819
  fromSubquery(subquery, alias, columnAliases) {
6788
6820
  const subAst = resolveSelectQuery(subquery);
@@ -6795,6 +6827,13 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
6795
6827
  * @param args - Optional function arguments
6796
6828
  * @param alias - Optional alias for the function table
6797
6829
  * @param options - Optional function-table metadata (lateral, ordinality, column aliases, schema)
6830
+ * @example
6831
+ * qb.fromFunctionTable(
6832
+ * 'generate_series',
6833
+ * [literal(1), literal(10), literal(1)],
6834
+ * 'series',
6835
+ * { columnAliases: ['value'] }
6836
+ * );
6798
6837
  */
6799
6838
  fromFunctionTable(name, args = [], alias, options) {
6800
6839
  const nextContext = this.fromFacet.fromFunctionTable(this.context, name, args, alias, options);
@@ -6805,6 +6844,12 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
6805
6844
  * @param alias - Alias for the subquery column
6806
6845
  * @param sub - Query builder or query node for the subquery
6807
6846
  * @returns New query builder instance with the subquery selection
6847
+ * @example
6848
+ * const postCount = new SelectQueryBuilder(postTable)
6849
+ * .select(count(postTable.columns.id))
6850
+ * .where(eq(postTable.columns.userId, col('u.id')));
6851
+ * qb.select('id', 'name')
6852
+ * .selectSubquery('postCount', postCount);
6808
6853
  */
6809
6854
  selectSubquery(alias, sub2) {
6810
6855
  const query = resolveSelectQuery(sub2);
@@ -6818,6 +6863,15 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
6818
6863
  * @param joinKind - Join kind (defaults to INNER)
6819
6864
  * @param columnAliases - Optional column alias list for the derived table
6820
6865
  * @returns New query builder instance with the derived-table join
6866
+ * @example
6867
+ * const activeUsers = new SelectQueryBuilder(userTable)
6868
+ * .where(eq(userTable.columns.active, true));
6869
+ * qb.joinSubquery(
6870
+ * activeUsers,
6871
+ * 'au',
6872
+ * eq(col('t.userId'), col('au.id')),
6873
+ * JOIN_KINDS.LEFT
6874
+ * );
6821
6875
  */
6822
6876
  joinSubquery(subquery, alias, condition, joinKind = JOIN_KINDS.INNER, columnAliases) {
6823
6877
  const subAst = resolveSelectQuery(subquery);
@@ -6832,6 +6886,15 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
6832
6886
  * @param condition - Join condition expression
6833
6887
  * @param joinKind - Kind of join (defaults to INNER)
6834
6888
  * @param options - Optional metadata (lateral, ordinality, column aliases, schema)
6889
+ * @example
6890
+ * qb.joinFunctionTable(
6891
+ * 'generate_series',
6892
+ * [literal(1), literal(10)],
6893
+ * 'gs',
6894
+ * eq(col('t.value'), col('gs.value')),
6895
+ * JOIN_KINDS.INNER,
6896
+ * { columnAliases: ['value'] }
6897
+ * );
6835
6898
  */
6836
6899
  joinFunctionTable(name, args = [], alias, condition, joinKind = JOIN_KINDS.INNER, options) {
6837
6900
  const nextContext = this.joinFacet.joinFunctionTable(this.context, name, args, alias, condition, joinKind, options);
@@ -6842,6 +6905,11 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
6842
6905
  * @param table - Table to join
6843
6906
  * @param condition - Join condition expression
6844
6907
  * @returns New query builder instance with the INNER JOIN
6908
+ * @example
6909
+ * qb.innerJoin(
6910
+ * postTable,
6911
+ * eq(userTable.columns.id, postTable.columns.userId)
6912
+ * );
6845
6913
  */
6846
6914
  innerJoin(table, condition) {
6847
6915
  const nextContext = this.joinFacet.applyJoin(this.context, table, condition, JOIN_KINDS.INNER);
@@ -6852,6 +6920,11 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
6852
6920
  * @param table - Table to join
6853
6921
  * @param condition - Join condition expression
6854
6922
  * @returns New query builder instance with the LEFT JOIN
6923
+ * @example
6924
+ * qb.leftJoin(
6925
+ * postTable,
6926
+ * eq(userTable.columns.id, postTable.columns.userId)
6927
+ * );
6855
6928
  */
6856
6929
  leftJoin(table, condition) {
6857
6930
  const nextContext = this.joinFacet.applyJoin(this.context, table, condition, JOIN_KINDS.LEFT);
@@ -6862,6 +6935,11 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
6862
6935
  * @param table - Table to join
6863
6936
  * @param condition - Join condition expression
6864
6937
  * @returns New query builder instance with the RIGHT JOIN
6938
+ * @example
6939
+ * qb.rightJoin(
6940
+ * postTable,
6941
+ * eq(userTable.columns.id, postTable.columns.userId)
6942
+ * );
6865
6943
  */
6866
6944
  rightJoin(table, condition) {
6867
6945
  const nextContext = this.joinFacet.applyJoin(this.context, table, condition, JOIN_KINDS.RIGHT);
@@ -6872,6 +6950,8 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
6872
6950
  * @param relationName - Name of the relationship to match
6873
6951
  * @param predicate - Optional predicate expression
6874
6952
  * @returns New query builder instance with the relationship match
6953
+ * @example
6954
+ * qb.match('posts', eq(postTable.columns.published, true));
6875
6955
  */
6876
6956
  match(relationName, predicate) {
6877
6957
  const nextContext = this.relationFacet.match(this.context, relationName, predicate);
@@ -6883,6 +6963,10 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
6883
6963
  * @param joinKind - Type of join (defaults to INNER)
6884
6964
  * @param extraCondition - Optional additional join condition
6885
6965
  * @returns New query builder instance with the relationship join
6966
+ * @example
6967
+ * qb.joinRelation('posts', JOIN_KINDS.LEFT);
6968
+ * @example
6969
+ * qb.joinRelation('posts', JOIN_KINDS.INNER, eq(postTable.columns.published, true));
6886
6970
  */
6887
6971
  joinRelation(relationName, joinKind = JOIN_KINDS.INNER, extraCondition) {
6888
6972
  const nextContext = this.relationFacet.joinRelation(this.context, relationName, joinKind, extraCondition);
@@ -6893,6 +6977,15 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
6893
6977
  * @param relationName - Name of the relationship to include
6894
6978
  * @param options - Optional include options
6895
6979
  * @returns New query builder instance with the relationship inclusion
6980
+ * @example
6981
+ * qb.include('posts');
6982
+ * @example
6983
+ * qb.include('posts', { columns: ['id', 'title', 'published'] });
6984
+ * @example
6985
+ * qb.include('posts', {
6986
+ * columns: ['id', 'title'],
6987
+ * where: eq(postTable.columns.published, true)
6988
+ * });
6896
6989
  */
6897
6990
  include(relationName, options) {
6898
6991
  const nextContext = this.relationFacet.include(this.context, relationName, options);
@@ -6903,6 +6996,11 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
6903
6996
  * @param relationName - Name of the relation to include lazily
6904
6997
  * @param options - Optional include options for lazy loading
6905
6998
  * @returns New query builder instance with lazy relation inclusion
6999
+ * @example
7000
+ * const qb = new SelectQueryBuilder(userTable).includeLazy('posts');
7001
+ * const users = await qb.execute(session);
7002
+ * // Access posts later - they will be loaded on demand
7003
+ * const posts = await users[0].posts;
6906
7004
  */
6907
7005
  includeLazy(relationName, options) {
6908
7006
  let nextContext = this.context;
@@ -6932,6 +7030,8 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
6932
7030
  }
6933
7031
  /**
6934
7032
  * Convenience alias for including only specific columns from a relation.
7033
+ * @example
7034
+ * qb.includePick('posts', ['id', 'title', 'createdAt']);
6935
7035
  */
6936
7036
  includePick(relationName, cols) {
6937
7037
  const options = { columns: cols };
@@ -6941,6 +7041,11 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
6941
7041
  * Selects columns for the root table and relations from an array of entries
6942
7042
  * @param config - Configuration array for deep column selection
6943
7043
  * @returns New query builder instance with deep column selections
7044
+ * @example
7045
+ * qb.selectColumnsDeep([
7046
+ * { type: 'root', columns: ['id', 'name'] },
7047
+ * { type: 'relation', relationName: 'posts', columns: ['id', 'title'] }
7048
+ * ]);
6944
7049
  */
6945
7050
  selectColumnsDeep(config) {
6946
7051
  let currBuilder = this;
@@ -6979,6 +7084,10 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
6979
7084
  * Executes the query and returns hydrated results
6980
7085
  * @param ctx - ORM session context
6981
7086
  * @returns Promise of entity instances
7087
+ * @example
7088
+ * const users = await qb.select('id', 'name')
7089
+ * .where(eq(userTable.columns.active, true))
7090
+ * .execute(session);
6982
7091
  */
6983
7092
  async execute(ctx) {
6984
7093
  return executeHydrated(ctx, this);
@@ -7006,6 +7115,10 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
7006
7115
  * @param execCtx - Execution context
7007
7116
  * @param hydCtx - Hydration context
7008
7117
  * @returns Promise of entity instances
7118
+ * @example
7119
+ * const execCtx = new ExecutionContext(session);
7120
+ * const hydCtx = new HydrationContext();
7121
+ * const users = await qb.executeWithContexts(execCtx, hydCtx);
7009
7122
  */
7010
7123
  async executeWithContexts(execCtx, hydCtx) {
7011
7124
  return executeHydratedWithContexts(execCtx, hydCtx, this);
@@ -7014,6 +7127,13 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
7014
7127
  * Adds a WHERE condition to the query
7015
7128
  * @param expr - Expression for the WHERE clause
7016
7129
  * @returns New query builder instance with the WHERE condition
7130
+ * @example
7131
+ * qb.where(eq(userTable.columns.id, 1));
7132
+ * @example
7133
+ * qb.where(and(
7134
+ * eq(userTable.columns.active, true),
7135
+ * gt(userTable.columns.createdAt, subDays(now(), 30))
7136
+ * ));
7017
7137
  */
7018
7138
  where(expr) {
7019
7139
  const nextContext = this.predicateFacet.where(this.context, expr);
@@ -7023,6 +7143,9 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
7023
7143
  * Adds a GROUP BY clause to the query
7024
7144
  * @param term - Column definition or ordering term to group by
7025
7145
  * @returns New query builder instance with the GROUP BY clause
7146
+ * @example
7147
+ * qb.select('departmentId', count(userTable.columns.id))
7148
+ * .groupBy(userTable.columns.departmentId);
7026
7149
  */
7027
7150
  groupBy(term) {
7028
7151
  const nextContext = this.predicateFacet.groupBy(this.context, term);
@@ -7032,6 +7155,10 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
7032
7155
  * Adds a HAVING condition to the query
7033
7156
  * @param expr - Expression for the HAVING clause
7034
7157
  * @returns New query builder instance with the HAVING condition
7158
+ * @example
7159
+ * qb.select('departmentId', count(userTable.columns.id))
7160
+ * .groupBy(userTable.columns.departmentId)
7161
+ * .having(gt(count(userTable.columns.id), 5));
7035
7162
  */
7036
7163
  having(expr) {
7037
7164
  const nextContext = this.predicateFacet.having(this.context, expr);
@@ -7054,6 +7181,10 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
7054
7181
  * Adds a DISTINCT clause to the query
7055
7182
  * @param cols - Columns to make distinct
7056
7183
  * @returns New query builder instance with the DISTINCT clause
7184
+ * @example
7185
+ * qb.distinct(userTable.columns.email);
7186
+ * @example
7187
+ * qb.distinct(userTable.columns.firstName, userTable.columns.lastName);
7057
7188
  */
7058
7189
  distinct(...cols) {
7059
7190
  return this.clone(this.projectionFacet.distinct(this.context, cols));
@@ -7062,6 +7193,10 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
7062
7193
  * Adds a LIMIT clause to the query
7063
7194
  * @param n - Maximum number of rows to return
7064
7195
  * @returns New query builder instance with the LIMIT clause
7196
+ * @example
7197
+ * qb.limit(10);
7198
+ * @example
7199
+ * qb.limit(20).offset(40); // Pagination: page 3 with 20 items per page
7065
7200
  */
7066
7201
  limit(n) {
7067
7202
  const nextContext = this.predicateFacet.limit(this.context, n);
@@ -7071,6 +7206,10 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
7071
7206
  * Adds an OFFSET clause to the query
7072
7207
  * @param n - Number of rows to skip
7073
7208
  * @returns New query builder instance with the OFFSET clause
7209
+ * @example
7210
+ * qb.offset(10);
7211
+ * @example
7212
+ * qb.limit(20).offset(40); // Pagination: page 3 with 20 items per page
7074
7213
  */
7075
7214
  offset(n) {
7076
7215
  const nextContext = this.predicateFacet.offset(this.context, n);
@@ -7080,6 +7219,12 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
7080
7219
  * Combines this query with another using UNION
7081
7220
  * @param query - Query to union with
7082
7221
  * @returns New query builder instance with the set operation
7222
+ * @example
7223
+ * const activeUsers = new SelectQueryBuilder(userTable)
7224
+ * .where(eq(userTable.columns.active, true));
7225
+ * const inactiveUsers = new SelectQueryBuilder(userTable)
7226
+ * .where(eq(userTable.columns.active, false));
7227
+ * qb.union(activeUsers).union(inactiveUsers);
7083
7228
  */
7084
7229
  union(query) {
7085
7230
  return this.clone(this.applySetOperation("UNION", query));
@@ -7088,6 +7233,10 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
7088
7233
  * Combines this query with another using UNION ALL
7089
7234
  * @param query - Query to union with
7090
7235
  * @returns New query builder instance with the set operation
7236
+ * @example
7237
+ * const q1 = new SelectQueryBuilder(userTable).where(gt(userTable.columns.score, 80));
7238
+ * const q2 = new SelectQueryBuilder(userTable).where(lt(userTable.columns.score, 20));
7239
+ * qb.unionAll(q1).unionAll(q2);
7091
7240
  */
7092
7241
  unionAll(query) {
7093
7242
  return this.clone(this.applySetOperation("UNION ALL", query));
@@ -7096,6 +7245,12 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
7096
7245
  * Combines this query with another using INTERSECT
7097
7246
  * @param query - Query to intersect with
7098
7247
  * @returns New query builder instance with the set operation
7248
+ * @example
7249
+ * const activeUsers = new SelectQueryBuilder(userTable)
7250
+ * .where(eq(userTable.columns.active, true));
7251
+ * const premiumUsers = new SelectQueryBuilder(userTable)
7252
+ * .where(eq(userTable.columns.premium, true));
7253
+ * qb.intersect(activeUsers).intersect(premiumUsers);
7099
7254
  */
7100
7255
  intersect(query) {
7101
7256
  return this.clone(this.applySetOperation("INTERSECT", query));
@@ -7104,6 +7259,11 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
7104
7259
  * Combines this query with another using EXCEPT
7105
7260
  * @param query - Query to subtract
7106
7261
  * @returns New query builder instance with the set operation
7262
+ * @example
7263
+ * const allUsers = new SelectQueryBuilder(userTable);
7264
+ * const inactiveUsers = new SelectQueryBuilder(userTable)
7265
+ * .where(eq(userTable.columns.active, false));
7266
+ * qb.except(allUsers).except(inactiveUsers); // Only active users
7107
7267
  */
7108
7268
  except(query) {
7109
7269
  return this.clone(this.applySetOperation("EXCEPT", query));
@@ -7112,6 +7272,10 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
7112
7272
  * Adds a WHERE EXISTS condition to the query
7113
7273
  * @param subquery - Subquery to check for existence
7114
7274
  * @returns New query builder instance with the WHERE EXISTS condition
7275
+ * @example
7276
+ * const postsQuery = new SelectQueryBuilder(postTable)
7277
+ * .where(eq(postTable.columns.userId, col('u.id')));
7278
+ * qb.whereExists(postsQuery);
7115
7279
  */
7116
7280
  whereExists(subquery, correlate) {
7117
7281
  const subAst = resolveSelectQuery(subquery);
@@ -7122,6 +7286,10 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
7122
7286
  * Adds a WHERE NOT EXISTS condition to the query
7123
7287
  * @param subquery - Subquery to check for non-existence
7124
7288
  * @returns New query builder instance with the WHERE NOT EXISTS condition
7289
+ * @example
7290
+ * const postsQuery = new SelectQueryBuilder(postTable)
7291
+ * .where(eq(postTable.columns.userId, col('u.id')));
7292
+ * qb.whereNotExists(postsQuery); // Users without posts
7125
7293
  */
7126
7294
  whereNotExists(subquery, correlate) {
7127
7295
  const subAst = resolveSelectQuery(subquery);
@@ -7176,6 +7344,11 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
7176
7344
  * Compiles the query to SQL for a specific dialect
7177
7345
  * @param dialect - Database dialect to compile for
7178
7346
  * @returns Compiled query with SQL and parameters
7347
+ * @example
7348
+ * const compiled = qb.select('id', 'name')
7349
+ * .where(eq(userTable.columns.active, true))
7350
+ * .compile('postgres');
7351
+ * console.log(compiled.sql); // SELECT "id", "name" FROM "users" WHERE "active" = true
7179
7352
  */
7180
7353
  compile(dialect) {
7181
7354
  const resolved = resolveDialectInput(dialect);
@@ -7185,6 +7358,11 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
7185
7358
  * Converts the query to SQL string for a specific dialect
7186
7359
  * @param dialect - Database dialect to generate SQL for
7187
7360
  * @returns SQL string representation of the query
7361
+ * @example
7362
+ * const sql = qb.select('id', 'name')
7363
+ * .where(eq(userTable.columns.active, true))
7364
+ * .toSql('postgres');
7365
+ * console.log(sql); // SELECT "id", "name" FROM "users" WHERE "active" = true
7188
7366
  */
7189
7367
  toSql(dialect) {
7190
7368
  return this.compile(dialect).sql;
@@ -7192,6 +7370,9 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
7192
7370
  /**
7193
7371
  * Gets the hydration plan for the query
7194
7372
  * @returns Hydration plan or undefined if none exists
7373
+ * @example
7374
+ * const plan = qb.include('posts').getHydrationPlan();
7375
+ * console.log(plan?.relations); // Information about included relations
7195
7376
  */
7196
7377
  getHydrationPlan() {
7197
7378
  return this.context.hydration.getPlan();
@@ -7199,6 +7380,10 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
7199
7380
  /**
7200
7381
  * Gets the Abstract Syntax Tree (AST) representation of the query
7201
7382
  * @returns Query AST with hydration applied
7383
+ * @example
7384
+ * const ast = qb.select('id', 'name').getAST();
7385
+ * console.log(ast.columns); // Array of column nodes
7386
+ * console.log(ast.from); // From clause information
7202
7387
  */
7203
7388
  getAST() {
7204
7389
  return this.context.hydration.applyToAst(this.context.state.ast);
@@ -8085,6 +8270,39 @@ var DeleteQueryBuilder = class _DeleteQueryBuilder {
8085
8270
  };
8086
8271
  var isTableSourceNode2 = (source) => typeof source.type === "string";
8087
8272
 
8273
+ // src/query/target.ts
8274
+ var resolveEntityTarget = (ctor) => {
8275
+ const table = getTableDefFromEntity(ctor);
8276
+ if (!table) {
8277
+ throw new Error(`Entity '${ctor.name}' is not registered with decorators`);
8278
+ }
8279
+ return table;
8280
+ };
8281
+ var resolveTable = (target) => {
8282
+ if (isTableDef(target)) {
8283
+ return target;
8284
+ }
8285
+ return resolveEntityTarget(target);
8286
+ };
8287
+
8288
+ // src/query/index.ts
8289
+ var selectFrom = (target) => {
8290
+ const table = resolveTable(target);
8291
+ return new SelectQueryBuilder(table);
8292
+ };
8293
+ var insertInto = (target) => {
8294
+ const table = resolveTable(target);
8295
+ return new InsertQueryBuilder(table);
8296
+ };
8297
+ var update = (target) => {
8298
+ const table = resolveTable(target);
8299
+ return new UpdateQueryBuilder(table);
8300
+ };
8301
+ var deleteFrom = (target) => {
8302
+ const table = resolveTable(target);
8303
+ return new DeleteQueryBuilder(table);
8304
+ };
8305
+
8088
8306
  // src/core/ddl/sql-writing.ts
8089
8307
  var resolvePrimaryKey = (table) => {
8090
8308
  if (Array.isArray(table.primaryKey) && table.primaryKey.length > 0) {
@@ -12703,6 +12921,7 @@ function createPooledExecutorFactory(opts) {
12703
12921
  dayOfWeek,
12704
12922
  defineTable,
12705
12923
  degrees,
12924
+ deleteFrom,
12706
12925
  denseRank,
12707
12926
  diffSchema,
12708
12927
  div,
@@ -12739,6 +12958,7 @@ function createPooledExecutorFactory(opts) {
12739
12958
  inList,
12740
12959
  inSubquery,
12741
12960
  initcap,
12961
+ insertInto,
12742
12962
  instr,
12743
12963
  introspectSchema,
12744
12964
  isCaseExpressionNode,
@@ -12827,6 +13047,7 @@ function createPooledExecutorFactory(opts) {
12827
13047
  rtrim,
12828
13048
  second,
12829
13049
  sel,
13050
+ selectFrom,
12830
13051
  selectFromEntity,
12831
13052
  setRelations,
12832
13053
  sha1,
@@ -12850,6 +13071,7 @@ function createPooledExecutorFactory(opts) {
12850
13071
  trunc,
12851
13072
  truncate,
12852
13073
  unixTimestamp,
13074
+ update,
12853
13075
  upper,
12854
13076
  utcNow,
12855
13077
  valueToOperand,