drizzle-orm 0.29.0-d615df5 → 0.29.0-e4ad266

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 (68) hide show
  1. package/mysql-core/query-builders/query.cjs +1 -9
  2. package/mysql-core/query-builders/query.cjs.map +1 -1
  3. package/mysql-core/query-builders/query.d.cts +0 -1
  4. package/mysql-core/query-builders/query.d.ts +0 -1
  5. package/mysql-core/query-builders/query.js +1 -9
  6. package/mysql-core/query-builders/query.js.map +1 -1
  7. package/mysql-core/view.cjs +2 -2
  8. package/mysql-core/view.cjs.map +1 -1
  9. package/mysql-core/view.d.cts +1 -1
  10. package/mysql-core/view.d.ts +1 -1
  11. package/mysql-core/view.js +2 -2
  12. package/mysql-core/view.js.map +1 -1
  13. package/mysql-proxy/migrator.cjs +2 -2
  14. package/mysql-proxy/migrator.cjs.map +1 -1
  15. package/mysql-proxy/migrator.js +2 -2
  16. package/mysql-proxy/migrator.js.map +1 -1
  17. package/package.json +1 -25
  18. package/pg-core/dialect.cjs +1 -1
  19. package/pg-core/dialect.cjs.map +1 -1
  20. package/pg-core/dialect.js +1 -1
  21. package/pg-core/dialect.js.map +1 -1
  22. package/pg-core/query-builders/delete.cjs.map +1 -1
  23. package/pg-core/query-builders/delete.js.map +1 -1
  24. package/pg-core/query-builders/insert.cjs.map +1 -1
  25. package/pg-core/query-builders/insert.js.map +1 -1
  26. package/pg-core/query-builders/query.cjs +2 -9
  27. package/pg-core/query-builders/query.cjs.map +1 -1
  28. package/pg-core/query-builders/query.d.cts +0 -1
  29. package/pg-core/query-builders/query.d.ts +0 -1
  30. package/pg-core/query-builders/query.js +2 -9
  31. package/pg-core/query-builders/query.js.map +1 -1
  32. package/pg-core/query-builders/update.cjs.map +1 -1
  33. package/pg-core/query-builders/update.js.map +1 -1
  34. package/pg-proxy/migrator.cjs +1 -1
  35. package/pg-proxy/migrator.cjs.map +1 -1
  36. package/pg-proxy/migrator.js +1 -1
  37. package/pg-proxy/migrator.js.map +1 -1
  38. package/sql/index.cjs +1 -3
  39. package/sql/index.cjs.map +1 -1
  40. package/sql/index.d.cts +0 -1
  41. package/sql/index.d.ts +0 -1
  42. package/sql/index.js +0 -1
  43. package/sql/index.js.map +1 -1
  44. package/sql/sql.cjs.map +1 -1
  45. package/sql/sql.js.map +1 -1
  46. package/sqlite-core/query-builders/delete.cjs.map +1 -1
  47. package/sqlite-core/query-builders/delete.js.map +1 -1
  48. package/sqlite-core/query-builders/insert.cjs.map +1 -1
  49. package/sqlite-core/query-builders/insert.js.map +1 -1
  50. package/sqlite-core/query-builders/select.types.cjs.map +1 -1
  51. package/sqlite-core/query-builders/update.cjs.map +1 -1
  52. package/sqlite-core/query-builders/update.js.map +1 -1
  53. package/version.cjs +1 -1
  54. package/version.d.cts +1 -1
  55. package/version.d.ts +1 -1
  56. package/version.js +1 -1
  57. package/sql/functions/aggregate.cjs +0 -69
  58. package/sql/functions/aggregate.cjs.map +0 -1
  59. package/sql/functions/aggregate.d.cts +0 -104
  60. package/sql/functions/aggregate.d.ts +0 -104
  61. package/sql/functions/aggregate.js +0 -38
  62. package/sql/functions/aggregate.js.map +0 -1
  63. package/sql/functions/index.cjs +0 -23
  64. package/sql/functions/index.cjs.map +0 -1
  65. package/sql/functions/index.d.cts +0 -1
  66. package/sql/functions/index.d.ts +0 -1
  67. package/sql/functions/index.js +0 -2
  68. package/sql/functions/index.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/sqlite-core/query-builders/update.ts"],"sourcesContent":["import type { GetColumnData } from '~/column.ts';\nimport { entityKind } from '~/entity.ts';\nimport type { SelectResultFields } from '~/query-builders/select.types.ts';\nimport { QueryPromise } from '~/query-promise.ts';\nimport type { RunnableQuery } from '~/runnable-query.ts';\nimport type { Query, SQL, SQLWrapper } from '~/sql/sql.ts';\nimport type { SQLiteDialect } from '~/sqlite-core/dialect.ts';\nimport type { SQLitePreparedQuery, SQLiteSession } from '~/sqlite-core/session.ts';\nimport { SQLiteTable } from '~/sqlite-core/table.ts';\nimport { type DrizzleTypeError, mapUpdateSet, orderSelectedFields, type UpdateSet } from '~/utils.ts';\nimport type { SelectedFields, SelectedFieldsOrdered } from './select.types.ts';\nimport type { SQLiteColumn } from '../columns/common.ts';\n\nexport interface SQLiteUpdateConfig {\n\twhere?: SQL | undefined;\n\tset: UpdateSet;\n\ttable: SQLiteTable;\n\treturning?: SelectedFieldsOrdered;\n}\n\nexport type SQLiteUpdateSetSource<TTable extends SQLiteTable> =\n\t& {\n\t\t[Key in keyof TTable['_']['columns']]?:\n\t\t\t| GetColumnData<TTable['_']['columns'][Key], 'query'>\n\t\t\t| SQL;\n\t}\n\t& {};\n\nexport class SQLiteUpdateBuilder<\n\tTTable extends SQLiteTable,\n\tTResultType extends 'sync' | 'async',\n\tTRunResult,\n> {\n\tstatic readonly [entityKind]: string = 'SQLiteUpdateBuilder';\n\n\tdeclare readonly _: {\n\t\treadonly table: TTable;\n\t};\n\n\tconstructor(\n\t\tprotected table: TTable,\n\t\tprotected session: SQLiteSession<any, any, any, any>,\n\t\tprotected dialect: SQLiteDialect,\n\t) {}\n\n\tset(values: SQLiteUpdateSetSource<TTable>): SQLiteUpdateBase<TTable, TResultType, TRunResult> {\n\t\treturn new SQLiteUpdateBase(this.table, mapUpdateSet(this.table, values), this.session, this.dialect);\n\t}\n}\n\nexport type SQLiteUpdateWithout<\n\tT extends AnySQLiteUpdate,\n\tTDynamic extends boolean,\n\tK extends keyof T & string,\n> = TDynamic extends true ? T : Omit<\n\tSQLiteUpdateBase<\n\t\tT['_']['table'],\n\t\tT['_']['resultType'],\n\t\tT['_']['runResult'],\n\t\tT['_']['returning'],\n\t\tTDynamic,\n\t\tT['_']['excludedMethods'] | K\n\t>,\n\tT['_']['excludedMethods'] | K\n>;\n\nexport type SQLiteUpdateReturningAll<T extends AnySQLiteUpdate, TDynamic extends boolean> = SQLiteUpdateWithout<\n\tSQLiteUpdateBase<\n\t\tT['_']['table'],\n\t\tT['_']['resultType'],\n\t\tT['_']['runResult'],\n\t\tT['_']['table']['$inferSelect'],\n\t\tTDynamic,\n\t\tT['_']['excludedMethods']\n\t>,\n\tTDynamic,\n\t'returning'\n>;\n\nexport type SQLiteUpdateReturning<\n\tT extends AnySQLiteUpdate,\n\tTDynamic extends boolean,\n\tTSelectedFields extends SelectedFields,\n> = SQLiteUpdateWithout<\n\tSQLiteUpdateBase<\n\t\tT['_']['table'],\n\t\tT['_']['resultType'],\n\t\tT['_']['runResult'],\n\t\tSelectResultFields<TSelectedFields>,\n\t\tTDynamic,\n\t\tT['_']['excludedMethods']\n\t>,\n\tTDynamic,\n\t'returning'\n>;\n\nexport type SQLiteUpdateExecute<T extends AnySQLiteUpdate> = T['_']['returning'] extends undefined ? T['_']['runResult']\n\t: T['_']['returning'][];\n\nexport type SQLiteUpdatePrepare<T extends AnySQLiteUpdate> = SQLitePreparedQuery<\n\t{\n\t\ttype: T['_']['resultType'];\n\t\trun: T['_']['runResult'];\n\t\tall: T['_']['returning'] extends undefined ? DrizzleTypeError<'.all() cannot be used without .returning()'>\n\t\t\t: T['_']['returning'][];\n\t\tget: T['_']['returning'] extends undefined ? DrizzleTypeError<'.get() cannot be used without .returning()'>\n\t\t\t: T['_']['returning'];\n\t\tvalues: T['_']['returning'] extends undefined ? DrizzleTypeError<'.values() cannot be used without .returning()'>\n\t\t\t: any[][];\n\t\texecute: SQLiteUpdateExecute<T>;\n\t}\n>;\n\nexport type SQLiteUpdateDynamic<T extends AnySQLiteUpdate> = SQLiteUpdate<\n\tT['_']['table'],\n\tT['_']['resultType'],\n\tT['_']['runResult'],\n\tT['_']['returning']\n>;\n\nexport type SQLiteUpdate<\n\tTTable extends SQLiteTable = SQLiteTable,\n\tTResultType extends 'sync' | 'async' = 'sync' | 'async',\n\tTRunResult = any,\n\tTReturning extends Record<string, unknown> | undefined = Record<string, unknown> | undefined,\n> = SQLiteUpdateBase<TTable, TResultType, TRunResult, TReturning, true, never>;\n\ntype AnySQLiteUpdate = SQLiteUpdateBase<any, any, any, any, any, any>;\n\nexport interface SQLiteUpdateBase<\n\tTTable extends SQLiteTable = SQLiteTable,\n\tTResultType extends 'sync' | 'async' = 'sync' | 'async',\n\tTRunResult = unknown,\n\tTReturning = undefined,\n\tTDynamic extends boolean = false,\n\tTExcludedMethods extends string = never,\n> extends SQLWrapper, QueryPromise<TReturning extends undefined ? TRunResult : TReturning[]> {\n\treadonly _: {\n\t\treadonly dialect: 'sqlite';\n\t\treadonly table: TTable;\n\t\treadonly resultType: TResultType;\n\t\treadonly runResult: TRunResult;\n\t\treadonly returning: TReturning;\n\t\treadonly dynamic: TDynamic;\n\t\treadonly excludedMethods: TExcludedMethods;\n\t\treadonly result: TReturning extends undefined ? TRunResult : TReturning[];\n\t};\n}\n\nexport class SQLiteUpdateBase<\n\tTTable extends SQLiteTable = SQLiteTable,\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tTResultType extends 'sync' | 'async' = 'sync' | 'async',\n\tTRunResult = unknown,\n\tTReturning = undefined,\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tTDynamic extends boolean = false,\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tTExcludedMethods extends string = never,\n> extends QueryPromise<TReturning extends undefined ? TRunResult : TReturning[]>\n\timplements RunnableQuery<TReturning extends undefined ? TRunResult : TReturning[], 'sqlite'>, SQLWrapper\n{\n\tstatic readonly [entityKind]: string = 'SQLiteUpdate';\n\n\t/** @internal */\n\tconfig: SQLiteUpdateConfig;\n\n\tconstructor(\n\t\ttable: TTable,\n\t\tset: UpdateSet,\n\t\tprivate session: SQLiteSession<any, any, any, any>,\n\t\tprivate dialect: SQLiteDialect,\n\t) {\n\t\tsuper();\n\t\tthis.config = { set, table };\n\t}\n\n\t/**\n\t * Adds a 'where' clause to the query.\n\t * \n\t * Calling this method will update only those rows that fulfill a specified condition.\n\t * \n\t * See docs: {@link https://orm.drizzle.team/docs/update}\n\t * \n\t * @param where the 'where' clause.\n\t * \n\t * @example\n\t * You can use conditional operators and `sql function` to filter the rows to be updated.\n\t * \n\t * ```ts\n\t * // Update all cars with green color\n\t * db.update(cars).set({ color: 'red' })\n\t * .where(eq(cars.color, 'green'));\n\t * // or\n\t * db.update(cars).set({ color: 'red' })\n\t * .where(sql`${cars.color} = 'green'`)\n\t * ```\n\t * \n\t * You can logically combine conditional operators with `and()` and `or()` operators:\n\t * \n\t * ```ts\n\t * // Update all BMW cars with a green color\n\t * db.update(cars).set({ color: 'red' })\n\t * .where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));\n\t * \n\t * // Update all cars with the green or blue color\n\t * db.update(cars).set({ color: 'red' })\n\t * .where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));\n\t * ```\n\t */\n\twhere(where: SQL | undefined): SQLiteUpdateWithout<this, TDynamic, 'where'> {\n\t\tthis.config.where = where;\n\t\treturn this as any;\n\t}\n\n\t/**\n\t * Adds a `returning` clause to the query.\n\t * \n\t * Calling this method will return the specified fields of the updated rows. If no fields are specified, all fields will be returned.\n\t * \n\t * See docs: {@link https://orm.drizzle.team/docs/update#update-with-returning}\n\t * \n\t * @example\n\t * ```ts\n\t * // Update all cars with the green color and return all fields\n\t * const updatedCars: Car[] = await db.update(cars)\n\t * .set({ color: 'red' })\n\t * .where(eq(cars.color, 'green'))\n\t * .returning();\n\t * \n\t * // Update all cars with the green color and return only their id and brand fields\n\t * const updatedCarsIdsAndBrands: { id: number, brand: string }[] = await db.update(cars)\n\t * .set({ color: 'red' })\n\t * .where(eq(cars.color, 'green'))\n\t * .returning({ id: cars.id, brand: cars.brand });\n\t * ```\n\t */\n\treturning(): SQLiteUpdateReturningAll<this, TDynamic>;\n\treturning<TSelectedFields extends SelectedFields>(\n\t\tfields: TSelectedFields,\n\t): SQLiteUpdateReturning<this, TDynamic, TSelectedFields>;\n\treturning(\n\t\tfields: SelectedFields = this.config.table[SQLiteTable.Symbol.Columns],\n\t): SQLiteUpdateWithout<AnySQLiteUpdate, TDynamic, 'returning'> {\n\t\tthis.config.returning = orderSelectedFields<SQLiteColumn>(fields);\n\t\treturn this as any;\n\t}\n\n\t/** @internal */\n\tgetSQL(): SQL {\n\t\treturn this.dialect.buildUpdateQuery(this.config);\n\t}\n\n\ttoSQL(): Query {\n\t\tconst { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());\n\t\treturn rest;\n\t}\n\n\tprepare(isOneTimeQuery?: boolean): SQLiteUpdatePrepare<this> {\n\t\treturn this.session[isOneTimeQuery ? 'prepareOneTimeQuery' : 'prepareQuery'](\n\t\t\tthis.dialect.sqlToQuery(this.getSQL()),\n\t\t\tthis.config.returning,\n\t\t\tthis.config.returning ? 'all' : 'run',\n\t\t) as SQLiteUpdatePrepare<this>;\n\t}\n\n\trun: ReturnType<this['prepare']>['run'] = (placeholderValues) => {\n\t\treturn this.prepare(true).run(placeholderValues);\n\t};\n\n\tall: ReturnType<this['prepare']>['all'] = (placeholderValues) => {\n\t\treturn this.prepare(true).all(placeholderValues);\n\t};\n\n\tget: ReturnType<this['prepare']>['get'] = (placeholderValues) => {\n\t\treturn this.prepare(true).get(placeholderValues);\n\t};\n\n\tvalues: ReturnType<this['prepare']>['values'] = (placeholderValues) => {\n\t\treturn this.prepare(true).values(placeholderValues);\n\t};\n\n\toverride async execute(): Promise<SQLiteUpdateExecute<this>> {\n\t\treturn (this.config.returning ? this.all() : this.run()) as SQLiteUpdateExecute<this>;\n\t}\n\n\t$dynamic(): SQLiteUpdateDynamic<this> {\n\t\treturn this as any;\n\t}\n}\n"],"mappings":"AACA,SAAS,kBAAkB;AAE3B,SAAS,oBAAoB;AAK7B,SAAS,mBAAmB;AAC5B,SAAgC,cAAc,2BAA2C;AAmBlF,MAAM,oBAIX;AAAA,EAOD,YACW,OACA,SACA,SACT;AAHS;AACA;AACA;AAAA,EACR;AAAA,EAVH,QAAiB,UAAU,IAAY;AAAA,EAYvC,IAAI,QAA0F;AAC7F,WAAO,IAAI,iBAAiB,KAAK,OAAO,aAAa,KAAK,OAAO,MAAM,GAAG,KAAK,SAAS,KAAK,OAAO;AAAA,EACrG;AACD;AAqGO,MAAM,yBAUH,aAEV;AAAA,EAMC,YACC,OACA,KACQ,SACA,SACP;AACD,UAAM;AAHE;AACA;AAGR,SAAK,SAAS,EAAE,KAAK,MAAM;AAAA,EAC5B;AAAA,EAbA,QAAiB,UAAU,IAAY;AAAA;AAAA,EAGvC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA6CA,MAAM,OAAsE;AAC3E,SAAK,OAAO,QAAQ;AACpB,WAAO;AAAA,EACR;AAAA,EA4BA,UACC,SAAyB,KAAK,OAAO,MAAM,YAAY,OAAO,OAAO,GACP;AAC9D,SAAK,OAAO,YAAY,oBAAkC,MAAM;AAChE,WAAO;AAAA,EACR;AAAA;AAAA,EAGA,SAAc;AACb,WAAO,KAAK,QAAQ,iBAAiB,KAAK,MAAM;AAAA,EACjD;AAAA,EAEA,QAAe;AACd,UAAM,EAAE,SAAS,UAAU,GAAG,KAAK,IAAI,KAAK,QAAQ,WAAW,KAAK,OAAO,CAAC;AAC5E,WAAO;AAAA,EACR;AAAA,EAEA,QAAQ,gBAAqD;AAC5D,WAAO,KAAK,QAAQ,iBAAiB,wBAAwB,cAAc;AAAA,MAC1E,KAAK,QAAQ,WAAW,KAAK,OAAO,CAAC;AAAA,MACrC,KAAK,OAAO;AAAA,MACZ,KAAK,OAAO,YAAY,QAAQ;AAAA,IACjC;AAAA,EACD;AAAA,EAEA,MAA0C,CAAC,sBAAsB;AAChE,WAAO,KAAK,QAAQ,IAAI,EAAE,IAAI,iBAAiB;AAAA,EAChD;AAAA,EAEA,MAA0C,CAAC,sBAAsB;AAChE,WAAO,KAAK,QAAQ,IAAI,EAAE,IAAI,iBAAiB;AAAA,EAChD;AAAA,EAEA,MAA0C,CAAC,sBAAsB;AAChE,WAAO,KAAK,QAAQ,IAAI,EAAE,IAAI,iBAAiB;AAAA,EAChD;AAAA,EAEA,SAAgD,CAAC,sBAAsB;AACtE,WAAO,KAAK,QAAQ,IAAI,EAAE,OAAO,iBAAiB;AAAA,EACnD;AAAA,EAEA,MAAe,UAA8C;AAC5D,WAAQ,KAAK,OAAO,YAAY,KAAK,IAAI,IAAI,KAAK,IAAI;AAAA,EACvD;AAAA,EAEA,WAAsC;AACrC,WAAO;AAAA,EACR;AACD;","names":[]}
1
+ {"version":3,"sources":["../../../src/sqlite-core/query-builders/update.ts"],"sourcesContent":["import type { GetColumnData } from '~/column.ts';\nimport { entityKind } from '~/entity.ts';\nimport type { SelectResultFields } from '~/query-builders/select.types.ts';\nimport { QueryPromise } from '~/query-promise.ts';\nimport type { RunnableQuery } from '~/runnable-query.ts';\nimport type { Query, SQL, SQLWrapper } from '~/sql/sql.ts';\nimport type { SQLiteDialect } from '~/sqlite-core/dialect.ts';\nimport type { SQLitePreparedQuery, SQLiteSession } from '~/sqlite-core/session.ts';\nimport { SQLiteTable } from '~/sqlite-core/table.ts';\nimport { type DrizzleTypeError, mapUpdateSet, orderSelectedFields, type UpdateSet } from '~/utils.ts';\nimport type { SelectedFields, SelectedFieldsOrdered } from './select.types.ts';\n\nexport interface SQLiteUpdateConfig {\n\twhere?: SQL | undefined;\n\tset: UpdateSet;\n\ttable: SQLiteTable;\n\treturning?: SelectedFieldsOrdered;\n}\n\nexport type SQLiteUpdateSetSource<TTable extends SQLiteTable> =\n\t& {\n\t\t[Key in keyof TTable['_']['columns']]?:\n\t\t\t| GetColumnData<TTable['_']['columns'][Key], 'query'>\n\t\t\t| SQL;\n\t}\n\t& {};\n\nexport class SQLiteUpdateBuilder<\n\tTTable extends SQLiteTable,\n\tTResultType extends 'sync' | 'async',\n\tTRunResult,\n> {\n\tstatic readonly [entityKind]: string = 'SQLiteUpdateBuilder';\n\n\tdeclare readonly _: {\n\t\treadonly table: TTable;\n\t};\n\n\tconstructor(\n\t\tprotected table: TTable,\n\t\tprotected session: SQLiteSession<any, any, any, any>,\n\t\tprotected dialect: SQLiteDialect,\n\t) {}\n\n\tset(values: SQLiteUpdateSetSource<TTable>): SQLiteUpdateBase<TTable, TResultType, TRunResult> {\n\t\treturn new SQLiteUpdateBase(this.table, mapUpdateSet(this.table, values), this.session, this.dialect);\n\t}\n}\n\nexport type SQLiteUpdateWithout<\n\tT extends AnySQLiteUpdate,\n\tTDynamic extends boolean,\n\tK extends keyof T & string,\n> = TDynamic extends true ? T : Omit<\n\tSQLiteUpdateBase<\n\t\tT['_']['table'],\n\t\tT['_']['resultType'],\n\t\tT['_']['runResult'],\n\t\tT['_']['returning'],\n\t\tTDynamic,\n\t\tT['_']['excludedMethods'] | K\n\t>,\n\tT['_']['excludedMethods'] | K\n>;\n\nexport type SQLiteUpdateReturningAll<T extends AnySQLiteUpdate, TDynamic extends boolean> = SQLiteUpdateWithout<\n\tSQLiteUpdateBase<\n\t\tT['_']['table'],\n\t\tT['_']['resultType'],\n\t\tT['_']['runResult'],\n\t\tT['_']['table']['$inferSelect'],\n\t\tTDynamic,\n\t\tT['_']['excludedMethods']\n\t>,\n\tTDynamic,\n\t'returning'\n>;\n\nexport type SQLiteUpdateReturning<\n\tT extends AnySQLiteUpdate,\n\tTDynamic extends boolean,\n\tTSelectedFields extends SelectedFields,\n> = SQLiteUpdateWithout<\n\tSQLiteUpdateBase<\n\t\tT['_']['table'],\n\t\tT['_']['resultType'],\n\t\tT['_']['runResult'],\n\t\tSelectResultFields<TSelectedFields>,\n\t\tTDynamic,\n\t\tT['_']['excludedMethods']\n\t>,\n\tTDynamic,\n\t'returning'\n>;\n\nexport type SQLiteUpdateExecute<T extends AnySQLiteUpdate> = T['_']['returning'] extends undefined ? T['_']['runResult']\n\t: T['_']['returning'][];\n\nexport type SQLiteUpdatePrepare<T extends AnySQLiteUpdate> = SQLitePreparedQuery<\n\t{\n\t\ttype: T['_']['resultType'];\n\t\trun: T['_']['runResult'];\n\t\tall: T['_']['returning'] extends undefined ? DrizzleTypeError<'.all() cannot be used without .returning()'>\n\t\t\t: T['_']['returning'][];\n\t\tget: T['_']['returning'] extends undefined ? DrizzleTypeError<'.get() cannot be used without .returning()'>\n\t\t\t: T['_']['returning'];\n\t\tvalues: T['_']['returning'] extends undefined ? DrizzleTypeError<'.values() cannot be used without .returning()'>\n\t\t\t: any[][];\n\t\texecute: SQLiteUpdateExecute<T>;\n\t}\n>;\n\nexport type SQLiteUpdateDynamic<T extends AnySQLiteUpdate> = SQLiteUpdate<\n\tT['_']['table'],\n\tT['_']['resultType'],\n\tT['_']['runResult'],\n\tT['_']['returning']\n>;\n\nexport type SQLiteUpdate<\n\tTTable extends SQLiteTable = SQLiteTable,\n\tTResultType extends 'sync' | 'async' = 'sync' | 'async',\n\tTRunResult = any,\n\tTReturning extends Record<string, unknown> | undefined = Record<string, unknown> | undefined,\n> = SQLiteUpdateBase<TTable, TResultType, TRunResult, TReturning, true, never>;\n\ntype AnySQLiteUpdate = SQLiteUpdateBase<any, any, any, any, any, any>;\n\nexport interface SQLiteUpdateBase<\n\tTTable extends SQLiteTable = SQLiteTable,\n\tTResultType extends 'sync' | 'async' = 'sync' | 'async',\n\tTRunResult = unknown,\n\tTReturning = undefined,\n\tTDynamic extends boolean = false,\n\tTExcludedMethods extends string = never,\n> extends SQLWrapper, QueryPromise<TReturning extends undefined ? TRunResult : TReturning[]> {\n\treadonly _: {\n\t\treadonly dialect: 'sqlite';\n\t\treadonly table: TTable;\n\t\treadonly resultType: TResultType;\n\t\treadonly runResult: TRunResult;\n\t\treadonly returning: TReturning;\n\t\treadonly dynamic: TDynamic;\n\t\treadonly excludedMethods: TExcludedMethods;\n\t\treadonly result: TReturning extends undefined ? TRunResult : TReturning[];\n\t};\n}\n\nexport class SQLiteUpdateBase<\n\tTTable extends SQLiteTable = SQLiteTable,\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tTResultType extends 'sync' | 'async' = 'sync' | 'async',\n\tTRunResult = unknown,\n\tTReturning = undefined,\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tTDynamic extends boolean = false,\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tTExcludedMethods extends string = never,\n> extends QueryPromise<TReturning extends undefined ? TRunResult : TReturning[]>\n\timplements RunnableQuery<TReturning extends undefined ? TRunResult : TReturning[], 'sqlite'>, SQLWrapper\n{\n\tstatic readonly [entityKind]: string = 'SQLiteUpdate';\n\n\t/** @internal */\n\tconfig: SQLiteUpdateConfig;\n\n\tconstructor(\n\t\ttable: TTable,\n\t\tset: UpdateSet,\n\t\tprivate session: SQLiteSession<any, any, any, any>,\n\t\tprivate dialect: SQLiteDialect,\n\t) {\n\t\tsuper();\n\t\tthis.config = { set, table };\n\t}\n\n\t/**\n\t * Adds a 'where' clause to the query.\n\t * \n\t * Calling this method will update only those rows that fulfill a specified condition.\n\t * \n\t * See docs: {@link https://orm.drizzle.team/docs/update}\n\t * \n\t * @param where the 'where' clause.\n\t * \n\t * @example\n\t * You can use conditional operators and `sql function` to filter the rows to be updated.\n\t * \n\t * ```ts\n\t * // Update all cars with green color\n\t * db.update(cars).set({ color: 'red' })\n\t * .where(eq(cars.color, 'green'));\n\t * // or\n\t * db.update(cars).set({ color: 'red' })\n\t * .where(sql`${cars.color} = 'green'`)\n\t * ```\n\t * \n\t * You can logically combine conditional operators with `and()` and `or()` operators:\n\t * \n\t * ```ts\n\t * // Update all BMW cars with a green color\n\t * db.update(cars).set({ color: 'red' })\n\t * .where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));\n\t * \n\t * // Update all cars with the green or blue color\n\t * db.update(cars).set({ color: 'red' })\n\t * .where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));\n\t * ```\n\t */\n\twhere(where: SQL | undefined): SQLiteUpdateWithout<this, TDynamic, 'where'> {\n\t\tthis.config.where = where;\n\t\treturn this as any;\n\t}\n\n\t/**\n\t * Adds a `returning` clause to the query.\n\t * \n\t * Calling this method will return the specified fields of the updated rows. If no fields are specified, all fields will be returned.\n\t * \n\t * See docs: {@link https://orm.drizzle.team/docs/update#update-with-returning}\n\t * \n\t * @example\n\t * ```ts\n\t * // Update all cars with the green color and return all fields\n\t * const updatedCars: Car[] = await db.update(cars)\n\t * .set({ color: 'red' })\n\t * .where(eq(cars.color, 'green'))\n\t * .returning();\n\t * \n\t * // Update all cars with the green color and return only their id and brand fields\n\t * const updatedCarsIdsAndBrands: { id: number, brand: string }[] = await db.update(cars)\n\t * .set({ color: 'red' })\n\t * .where(eq(cars.color, 'green'))\n\t * .returning({ id: cars.id, brand: cars.brand });\n\t * ```\n\t */\n\treturning(): SQLiteUpdateReturningAll<this, TDynamic>;\n\treturning<TSelectedFields extends SelectedFields>(\n\t\tfields: TSelectedFields,\n\t): SQLiteUpdateReturning<this, TDynamic, TSelectedFields>;\n\treturning(\n\t\tfields: SelectedFields = this.config.table[SQLiteTable.Symbol.Columns],\n\t): SQLiteUpdateWithout<AnySQLiteUpdate, TDynamic, 'returning'> {\n\t\tthis.config.returning = orderSelectedFields(fields);\n\t\treturn this as any;\n\t}\n\n\t/** @internal */\n\tgetSQL(): SQL {\n\t\treturn this.dialect.buildUpdateQuery(this.config);\n\t}\n\n\ttoSQL(): Query {\n\t\tconst { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());\n\t\treturn rest;\n\t}\n\n\tprepare(isOneTimeQuery?: boolean): SQLiteUpdatePrepare<this> {\n\t\treturn this.session[isOneTimeQuery ? 'prepareOneTimeQuery' : 'prepareQuery'](\n\t\t\tthis.dialect.sqlToQuery(this.getSQL()),\n\t\t\tthis.config.returning,\n\t\t\tthis.config.returning ? 'all' : 'run',\n\t\t) as SQLiteUpdatePrepare<this>;\n\t}\n\n\trun: ReturnType<this['prepare']>['run'] = (placeholderValues) => {\n\t\treturn this.prepare(true).run(placeholderValues);\n\t};\n\n\tall: ReturnType<this['prepare']>['all'] = (placeholderValues) => {\n\t\treturn this.prepare(true).all(placeholderValues);\n\t};\n\n\tget: ReturnType<this['prepare']>['get'] = (placeholderValues) => {\n\t\treturn this.prepare(true).get(placeholderValues);\n\t};\n\n\tvalues: ReturnType<this['prepare']>['values'] = (placeholderValues) => {\n\t\treturn this.prepare(true).values(placeholderValues);\n\t};\n\n\toverride async execute(): Promise<SQLiteUpdateExecute<this>> {\n\t\treturn (this.config.returning ? this.all() : this.run()) as SQLiteUpdateExecute<this>;\n\t}\n\n\t$dynamic(): SQLiteUpdateDynamic<this> {\n\t\treturn this as any;\n\t}\n}\n"],"mappings":"AACA,SAAS,kBAAkB;AAE3B,SAAS,oBAAoB;AAK7B,SAAS,mBAAmB;AAC5B,SAAgC,cAAc,2BAA2C;AAkBlF,MAAM,oBAIX;AAAA,EAOD,YACW,OACA,SACA,SACT;AAHS;AACA;AACA;AAAA,EACR;AAAA,EAVH,QAAiB,UAAU,IAAY;AAAA,EAYvC,IAAI,QAA0F;AAC7F,WAAO,IAAI,iBAAiB,KAAK,OAAO,aAAa,KAAK,OAAO,MAAM,GAAG,KAAK,SAAS,KAAK,OAAO;AAAA,EACrG;AACD;AAqGO,MAAM,yBAUH,aAEV;AAAA,EAMC,YACC,OACA,KACQ,SACA,SACP;AACD,UAAM;AAHE;AACA;AAGR,SAAK,SAAS,EAAE,KAAK,MAAM;AAAA,EAC5B;AAAA,EAbA,QAAiB,UAAU,IAAY;AAAA;AAAA,EAGvC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA6CA,MAAM,OAAsE;AAC3E,SAAK,OAAO,QAAQ;AACpB,WAAO;AAAA,EACR;AAAA,EA4BA,UACC,SAAyB,KAAK,OAAO,MAAM,YAAY,OAAO,OAAO,GACP;AAC9D,SAAK,OAAO,YAAY,oBAAoB,MAAM;AAClD,WAAO;AAAA,EACR;AAAA;AAAA,EAGA,SAAc;AACb,WAAO,KAAK,QAAQ,iBAAiB,KAAK,MAAM;AAAA,EACjD;AAAA,EAEA,QAAe;AACd,UAAM,EAAE,SAAS,UAAU,GAAG,KAAK,IAAI,KAAK,QAAQ,WAAW,KAAK,OAAO,CAAC;AAC5E,WAAO;AAAA,EACR;AAAA,EAEA,QAAQ,gBAAqD;AAC5D,WAAO,KAAK,QAAQ,iBAAiB,wBAAwB,cAAc;AAAA,MAC1E,KAAK,QAAQ,WAAW,KAAK,OAAO,CAAC;AAAA,MACrC,KAAK,OAAO;AAAA,MACZ,KAAK,OAAO,YAAY,QAAQ;AAAA,IACjC;AAAA,EACD;AAAA,EAEA,MAA0C,CAAC,sBAAsB;AAChE,WAAO,KAAK,QAAQ,IAAI,EAAE,IAAI,iBAAiB;AAAA,EAChD;AAAA,EAEA,MAA0C,CAAC,sBAAsB;AAChE,WAAO,KAAK,QAAQ,IAAI,EAAE,IAAI,iBAAiB;AAAA,EAChD;AAAA,EAEA,MAA0C,CAAC,sBAAsB;AAChE,WAAO,KAAK,QAAQ,IAAI,EAAE,IAAI,iBAAiB;AAAA,EAChD;AAAA,EAEA,SAAgD,CAAC,sBAAsB;AACtE,WAAO,KAAK,QAAQ,IAAI,EAAE,OAAO,iBAAiB;AAAA,EACnD;AAAA,EAEA,MAAe,UAA8C;AAC5D,WAAQ,KAAK,OAAO,YAAY,KAAK,IAAI,IAAI,KAAK,IAAI;AAAA,EACvD;AAAA,EAEA,WAAsC;AACrC,WAAO;AAAA,EACR;AACD;","names":[]}
package/version.cjs CHANGED
@@ -26,7 +26,7 @@ __export(version_exports, {
26
26
  module.exports = __toCommonJS(version_exports);
27
27
 
28
28
  // package.json
29
- var version = "0.29.0-d615df5";
29
+ var version = "0.29.0-e4ad266";
30
30
 
31
31
  // src/version.ts
32
32
  var compatibilityVersion = 6;
package/version.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- var version = "0.29.0-d615df5";
1
+ var version = "0.29.0-e4ad266";
2
2
 
3
3
  declare const compatibilityVersion = 6;
4
4
 
package/version.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- var version = "0.29.0-d615df5";
1
+ var version = "0.29.0-e4ad266";
2
2
 
3
3
  declare const compatibilityVersion = 6;
4
4
 
package/version.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // package.json
2
- var version = "0.29.0-d615df5";
2
+ var version = "0.29.0-e4ad266";
3
3
 
4
4
  // src/version.ts
5
5
  var compatibilityVersion = 6;
@@ -1,69 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var aggregate_exports = {};
20
- __export(aggregate_exports, {
21
- avg: () => avg,
22
- avgDistinct: () => avgDistinct,
23
- count: () => count,
24
- countDistinct: () => countDistinct,
25
- max: () => max,
26
- min: () => min,
27
- sum: () => sum,
28
- sumDistinct: () => sumDistinct
29
- });
30
- module.exports = __toCommonJS(aggregate_exports);
31
- var import_entity = require("../../entity.cjs");
32
- var import_sql = require("../sql.cjs");
33
- var import_column = require("../../column.cjs");
34
- function count(expression) {
35
- return import_sql.sql`count(${expression || import_sql.sql.raw("*")})`.mapWith(Number);
36
- }
37
- function countDistinct(expression) {
38
- return import_sql.sql`count(distinct ${expression})`.mapWith(Number);
39
- }
40
- function avg(expression) {
41
- return import_sql.sql`avg(${expression})`.mapWith(String);
42
- }
43
- function avgDistinct(expression) {
44
- return import_sql.sql`avg(distinct ${expression})`.mapWith(String);
45
- }
46
- function sum(expression) {
47
- return import_sql.sql`sum(${expression})`.mapWith(String);
48
- }
49
- function sumDistinct(expression) {
50
- return import_sql.sql`sum(distinct ${expression})`.mapWith(String);
51
- }
52
- function max(expression) {
53
- return import_sql.sql`max(${expression})`.mapWith((0, import_entity.is)(expression, import_column.Column) ? expression : String);
54
- }
55
- function min(expression) {
56
- return import_sql.sql`min(${expression})`.mapWith((0, import_entity.is)(expression, import_column.Column) ? expression : String);
57
- }
58
- // Annotate the CommonJS export names for ESM import in node:
59
- 0 && (module.exports = {
60
- avg,
61
- avgDistinct,
62
- count,
63
- countDistinct,
64
- max,
65
- min,
66
- sum,
67
- sumDistinct
68
- });
69
- //# sourceMappingURL=aggregate.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/sql/functions/aggregate.ts"],"sourcesContent":["import { is } from '~/entity.ts';\nimport { type SQL, sql, type SQLWrapper } from '../sql.ts';\nimport { type AnyColumn, Column } from '~/column.ts';\n\n/**\n * Returns the number of values in `expression`.\n *\n * ## Examples\n *\n * ```ts\n * // Number employees with null values\n * db.select({ value: count() }).from(employees)\n * // Number of employees where `name` is not null\n * db.select({ value: count(employees.name) }).from(employees)\n * ```\n * \n * @see countDistinct to get the number of non-duplicate values in `expression`\n */\nexport function count(expression?: SQLWrapper): SQL<number> {\n return sql`count(${expression || sql.raw('*')})`.mapWith(Number);\n}\n\n/**\n * Returns the number of non-duplicate values in `expression`.\n *\n * ## Examples\n *\n * ```ts\n * // Number of employees where `name` is distinct\n * db.select({ value: countDistinct(employees.name) }).from(employees)\n * ```\n * \n * @see count to get the number of values in `expression`, including duplicates\n */\nexport function countDistinct(expression: SQLWrapper): SQL<number> {\n return sql`count(distinct ${expression})`.mapWith(Number);\n}\n\n/**\n * Returns the average (arithmetic mean) of all non-null values in `expression`.\n *\n * ## Examples\n *\n * ```ts\n * // Average salary of an employee\n * db.select({ value: avg(employees.salary) }).from(employees)\n * ```\n * \n * @see avgDistinct to get the average of all non-null and non-duplicate values in `expression`\n */\nexport function avg(expression: SQLWrapper): SQL<string | null> {\n return sql`avg(${expression})`.mapWith(String);\n}\n\n/**\n * Returns the average (arithmetic mean) of all non-null and non-duplicate values in `expression`.\n *\n * ## Examples\n *\n * ```ts\n * // Average salary of an employee where `salary` is distinct\n * db.select({ value: avgDistinct(employees.salary) }).from(employees)\n * ```\n * \n * @see avg to get the average of all non-null values in `expression`, including duplicates\n */\nexport function avgDistinct(expression: SQLWrapper): SQL<string | null> {\n return sql`avg(distinct ${expression})`.mapWith(String);\n}\n\n/**\n * Returns the sum of all non-null values in `expression`.\n *\n * ## Examples\n *\n * ```ts\n * // Sum of every employee's salary\n * db.select({ value: sum(employees.salary) }).from(employees)\n * ```\n * \n * @see sumDistinct to get the sum of all non-null and non-duplicate values in `expression`\n */\nexport function sum(expression: SQLWrapper): SQL<string | null> {\n return sql`sum(${expression})`.mapWith(String);\n}\n\n/**\n * Returns the sum of all non-null and non-duplicate values in `expression`.\n *\n * ## Examples\n *\n * ```ts\n * // Sum of every employee's salary where `salary` is distinct (no duplicates)\n * db.select({ value: sumDistinct(employees.salary) }).from(employees)\n * ```\n * \n * @see sum to get the sum of all non-null values in `expression`, including duplicates\n */\nexport function sumDistinct(expression: SQLWrapper): SQL<string | null> {\n return sql`sum(distinct ${expression})`.mapWith(String);\n}\n\n/**\n * Returns the maximum value in `expression`.\n *\n * ## Examples\n *\n * ```ts\n * // The employee with the highest salary\n * db.select({ value: max(employees.salary) }).from(employees)\n * ```\n */\nexport function max<T extends SQLWrapper>(expression: T): SQL<(T extends AnyColumn ? T['_']['data'] : string) | null> {\n return sql`max(${expression})`.mapWith(is(expression, Column) ? expression : String) as any;\n}\n\n/**\n * Returns the minimum value in `expression`.\n *\n * ## Examples\n *\n * ```ts\n * // The employee with the lowest salary\n * db.select({ value: min(employees.salary) }).from(employees)\n * ```\n */\nexport function min<T extends SQLWrapper>(expression: T): SQL<(T extends AnyColumn ? T['_']['data'] : string) | null> {\n return sql`min(${expression})`.mapWith(is(expression, Column) ? expression : String) as any;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAmB;AACnB,iBAA+C;AAC/C,oBAAuC;AAgBhC,SAAS,MAAM,YAAsC;AAC1D,SAAO,uBAAY,cAAc,eAAI,IAAI,GAAG,CAAC,IAAI,QAAQ,MAAM;AACjE;AAcO,SAAS,cAAc,YAAqC;AACjE,SAAO,gCAAqB,UAAU,IAAI,QAAQ,MAAM;AAC1D;AAcO,SAAS,IAAI,YAA4C;AAC9D,SAAO,qBAAU,UAAU,IAAI,QAAQ,MAAM;AAC/C;AAcO,SAAS,YAAY,YAA4C;AACtE,SAAO,8BAAmB,UAAU,IAAI,QAAQ,MAAM;AACxD;AAcO,SAAS,IAAI,YAA4C;AAC9D,SAAO,qBAAU,UAAU,IAAI,QAAQ,MAAM;AAC/C;AAcO,SAAS,YAAY,YAA4C;AACtE,SAAO,8BAAmB,UAAU,IAAI,QAAQ,MAAM;AACxD;AAYO,SAAS,IAA0B,YAA4E;AACpH,SAAO,qBAAU,UAAU,IAAI,YAAQ,kBAAG,YAAY,oBAAM,IAAI,aAAa,MAAM;AACrF;AAYO,SAAS,IAA0B,YAA4E;AACpH,SAAO,qBAAU,UAAU,IAAI,YAAQ,kBAAG,YAAY,oBAAM,IAAI,aAAa,MAAM;AACrF;","names":[]}
@@ -1,104 +0,0 @@
1
- import { type SQL, type SQLWrapper } from "../sql.cjs";
2
- import { type AnyColumn } from "../../column.cjs";
3
- /**
4
- * Returns the number of values in `expression`.
5
- *
6
- * ## Examples
7
- *
8
- * ```ts
9
- * // Number employees with null values
10
- * db.select({ value: count() }).from(employees)
11
- * // Number of employees where `name` is not null
12
- * db.select({ value: count(employees.name) }).from(employees)
13
- * ```
14
- *
15
- * @see countDistinct to get the number of non-duplicate values in `expression`
16
- */
17
- export declare function count(expression?: SQLWrapper): SQL<number>;
18
- /**
19
- * Returns the number of non-duplicate values in `expression`.
20
- *
21
- * ## Examples
22
- *
23
- * ```ts
24
- * // Number of employees where `name` is distinct
25
- * db.select({ value: countDistinct(employees.name) }).from(employees)
26
- * ```
27
- *
28
- * @see count to get the number of values in `expression`, including duplicates
29
- */
30
- export declare function countDistinct(expression: SQLWrapper): SQL<number>;
31
- /**
32
- * Returns the average (arithmetic mean) of all non-null values in `expression`.
33
- *
34
- * ## Examples
35
- *
36
- * ```ts
37
- * // Average salary of an employee
38
- * db.select({ value: avg(employees.salary) }).from(employees)
39
- * ```
40
- *
41
- * @see avgDistinct to get the average of all non-null and non-duplicate values in `expression`
42
- */
43
- export declare function avg(expression: SQLWrapper): SQL<string | null>;
44
- /**
45
- * Returns the average (arithmetic mean) of all non-null and non-duplicate values in `expression`.
46
- *
47
- * ## Examples
48
- *
49
- * ```ts
50
- * // Average salary of an employee where `salary` is distinct
51
- * db.select({ value: avgDistinct(employees.salary) }).from(employees)
52
- * ```
53
- *
54
- * @see avg to get the average of all non-null values in `expression`, including duplicates
55
- */
56
- export declare function avgDistinct(expression: SQLWrapper): SQL<string | null>;
57
- /**
58
- * Returns the sum of all non-null values in `expression`.
59
- *
60
- * ## Examples
61
- *
62
- * ```ts
63
- * // Sum of every employee's salary
64
- * db.select({ value: sum(employees.salary) }).from(employees)
65
- * ```
66
- *
67
- * @see sumDistinct to get the sum of all non-null and non-duplicate values in `expression`
68
- */
69
- export declare function sum(expression: SQLWrapper): SQL<string | null>;
70
- /**
71
- * Returns the sum of all non-null and non-duplicate values in `expression`.
72
- *
73
- * ## Examples
74
- *
75
- * ```ts
76
- * // Sum of every employee's salary where `salary` is distinct (no duplicates)
77
- * db.select({ value: sumDistinct(employees.salary) }).from(employees)
78
- * ```
79
- *
80
- * @see sum to get the sum of all non-null values in `expression`, including duplicates
81
- */
82
- export declare function sumDistinct(expression: SQLWrapper): SQL<string | null>;
83
- /**
84
- * Returns the maximum value in `expression`.
85
- *
86
- * ## Examples
87
- *
88
- * ```ts
89
- * // The employee with the highest salary
90
- * db.select({ value: max(employees.salary) }).from(employees)
91
- * ```
92
- */
93
- export declare function max<T extends SQLWrapper>(expression: T): SQL<(T extends AnyColumn ? T['_']['data'] : string) | null>;
94
- /**
95
- * Returns the minimum value in `expression`.
96
- *
97
- * ## Examples
98
- *
99
- * ```ts
100
- * // The employee with the lowest salary
101
- * db.select({ value: min(employees.salary) }).from(employees)
102
- * ```
103
- */
104
- export declare function min<T extends SQLWrapper>(expression: T): SQL<(T extends AnyColumn ? T['_']['data'] : string) | null>;
@@ -1,104 +0,0 @@
1
- import { type SQL, type SQLWrapper } from "../sql.js";
2
- import { type AnyColumn } from "../../column.js";
3
- /**
4
- * Returns the number of values in `expression`.
5
- *
6
- * ## Examples
7
- *
8
- * ```ts
9
- * // Number employees with null values
10
- * db.select({ value: count() }).from(employees)
11
- * // Number of employees where `name` is not null
12
- * db.select({ value: count(employees.name) }).from(employees)
13
- * ```
14
- *
15
- * @see countDistinct to get the number of non-duplicate values in `expression`
16
- */
17
- export declare function count(expression?: SQLWrapper): SQL<number>;
18
- /**
19
- * Returns the number of non-duplicate values in `expression`.
20
- *
21
- * ## Examples
22
- *
23
- * ```ts
24
- * // Number of employees where `name` is distinct
25
- * db.select({ value: countDistinct(employees.name) }).from(employees)
26
- * ```
27
- *
28
- * @see count to get the number of values in `expression`, including duplicates
29
- */
30
- export declare function countDistinct(expression: SQLWrapper): SQL<number>;
31
- /**
32
- * Returns the average (arithmetic mean) of all non-null values in `expression`.
33
- *
34
- * ## Examples
35
- *
36
- * ```ts
37
- * // Average salary of an employee
38
- * db.select({ value: avg(employees.salary) }).from(employees)
39
- * ```
40
- *
41
- * @see avgDistinct to get the average of all non-null and non-duplicate values in `expression`
42
- */
43
- export declare function avg(expression: SQLWrapper): SQL<string | null>;
44
- /**
45
- * Returns the average (arithmetic mean) of all non-null and non-duplicate values in `expression`.
46
- *
47
- * ## Examples
48
- *
49
- * ```ts
50
- * // Average salary of an employee where `salary` is distinct
51
- * db.select({ value: avgDistinct(employees.salary) }).from(employees)
52
- * ```
53
- *
54
- * @see avg to get the average of all non-null values in `expression`, including duplicates
55
- */
56
- export declare function avgDistinct(expression: SQLWrapper): SQL<string | null>;
57
- /**
58
- * Returns the sum of all non-null values in `expression`.
59
- *
60
- * ## Examples
61
- *
62
- * ```ts
63
- * // Sum of every employee's salary
64
- * db.select({ value: sum(employees.salary) }).from(employees)
65
- * ```
66
- *
67
- * @see sumDistinct to get the sum of all non-null and non-duplicate values in `expression`
68
- */
69
- export declare function sum(expression: SQLWrapper): SQL<string | null>;
70
- /**
71
- * Returns the sum of all non-null and non-duplicate values in `expression`.
72
- *
73
- * ## Examples
74
- *
75
- * ```ts
76
- * // Sum of every employee's salary where `salary` is distinct (no duplicates)
77
- * db.select({ value: sumDistinct(employees.salary) }).from(employees)
78
- * ```
79
- *
80
- * @see sum to get the sum of all non-null values in `expression`, including duplicates
81
- */
82
- export declare function sumDistinct(expression: SQLWrapper): SQL<string | null>;
83
- /**
84
- * Returns the maximum value in `expression`.
85
- *
86
- * ## Examples
87
- *
88
- * ```ts
89
- * // The employee with the highest salary
90
- * db.select({ value: max(employees.salary) }).from(employees)
91
- * ```
92
- */
93
- export declare function max<T extends SQLWrapper>(expression: T): SQL<(T extends AnyColumn ? T['_']['data'] : string) | null>;
94
- /**
95
- * Returns the minimum value in `expression`.
96
- *
97
- * ## Examples
98
- *
99
- * ```ts
100
- * // The employee with the lowest salary
101
- * db.select({ value: min(employees.salary) }).from(employees)
102
- * ```
103
- */
104
- export declare function min<T extends SQLWrapper>(expression: T): SQL<(T extends AnyColumn ? T['_']['data'] : string) | null>;
@@ -1,38 +0,0 @@
1
- import { is } from "../../entity.js";
2
- import { sql } from "../sql.js";
3
- import { Column } from "../../column.js";
4
- function count(expression) {
5
- return sql`count(${expression || sql.raw("*")})`.mapWith(Number);
6
- }
7
- function countDistinct(expression) {
8
- return sql`count(distinct ${expression})`.mapWith(Number);
9
- }
10
- function avg(expression) {
11
- return sql`avg(${expression})`.mapWith(String);
12
- }
13
- function avgDistinct(expression) {
14
- return sql`avg(distinct ${expression})`.mapWith(String);
15
- }
16
- function sum(expression) {
17
- return sql`sum(${expression})`.mapWith(String);
18
- }
19
- function sumDistinct(expression) {
20
- return sql`sum(distinct ${expression})`.mapWith(String);
21
- }
22
- function max(expression) {
23
- return sql`max(${expression})`.mapWith(is(expression, Column) ? expression : String);
24
- }
25
- function min(expression) {
26
- return sql`min(${expression})`.mapWith(is(expression, Column) ? expression : String);
27
- }
28
- export {
29
- avg,
30
- avgDistinct,
31
- count,
32
- countDistinct,
33
- max,
34
- min,
35
- sum,
36
- sumDistinct
37
- };
38
- //# sourceMappingURL=aggregate.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/sql/functions/aggregate.ts"],"sourcesContent":["import { is } from '~/entity.ts';\nimport { type SQL, sql, type SQLWrapper } from '../sql.ts';\nimport { type AnyColumn, Column } from '~/column.ts';\n\n/**\n * Returns the number of values in `expression`.\n *\n * ## Examples\n *\n * ```ts\n * // Number employees with null values\n * db.select({ value: count() }).from(employees)\n * // Number of employees where `name` is not null\n * db.select({ value: count(employees.name) }).from(employees)\n * ```\n * \n * @see countDistinct to get the number of non-duplicate values in `expression`\n */\nexport function count(expression?: SQLWrapper): SQL<number> {\n return sql`count(${expression || sql.raw('*')})`.mapWith(Number);\n}\n\n/**\n * Returns the number of non-duplicate values in `expression`.\n *\n * ## Examples\n *\n * ```ts\n * // Number of employees where `name` is distinct\n * db.select({ value: countDistinct(employees.name) }).from(employees)\n * ```\n * \n * @see count to get the number of values in `expression`, including duplicates\n */\nexport function countDistinct(expression: SQLWrapper): SQL<number> {\n return sql`count(distinct ${expression})`.mapWith(Number);\n}\n\n/**\n * Returns the average (arithmetic mean) of all non-null values in `expression`.\n *\n * ## Examples\n *\n * ```ts\n * // Average salary of an employee\n * db.select({ value: avg(employees.salary) }).from(employees)\n * ```\n * \n * @see avgDistinct to get the average of all non-null and non-duplicate values in `expression`\n */\nexport function avg(expression: SQLWrapper): SQL<string | null> {\n return sql`avg(${expression})`.mapWith(String);\n}\n\n/**\n * Returns the average (arithmetic mean) of all non-null and non-duplicate values in `expression`.\n *\n * ## Examples\n *\n * ```ts\n * // Average salary of an employee where `salary` is distinct\n * db.select({ value: avgDistinct(employees.salary) }).from(employees)\n * ```\n * \n * @see avg to get the average of all non-null values in `expression`, including duplicates\n */\nexport function avgDistinct(expression: SQLWrapper): SQL<string | null> {\n return sql`avg(distinct ${expression})`.mapWith(String);\n}\n\n/**\n * Returns the sum of all non-null values in `expression`.\n *\n * ## Examples\n *\n * ```ts\n * // Sum of every employee's salary\n * db.select({ value: sum(employees.salary) }).from(employees)\n * ```\n * \n * @see sumDistinct to get the sum of all non-null and non-duplicate values in `expression`\n */\nexport function sum(expression: SQLWrapper): SQL<string | null> {\n return sql`sum(${expression})`.mapWith(String);\n}\n\n/**\n * Returns the sum of all non-null and non-duplicate values in `expression`.\n *\n * ## Examples\n *\n * ```ts\n * // Sum of every employee's salary where `salary` is distinct (no duplicates)\n * db.select({ value: sumDistinct(employees.salary) }).from(employees)\n * ```\n * \n * @see sum to get the sum of all non-null values in `expression`, including duplicates\n */\nexport function sumDistinct(expression: SQLWrapper): SQL<string | null> {\n return sql`sum(distinct ${expression})`.mapWith(String);\n}\n\n/**\n * Returns the maximum value in `expression`.\n *\n * ## Examples\n *\n * ```ts\n * // The employee with the highest salary\n * db.select({ value: max(employees.salary) }).from(employees)\n * ```\n */\nexport function max<T extends SQLWrapper>(expression: T): SQL<(T extends AnyColumn ? T['_']['data'] : string) | null> {\n return sql`max(${expression})`.mapWith(is(expression, Column) ? expression : String) as any;\n}\n\n/**\n * Returns the minimum value in `expression`.\n *\n * ## Examples\n *\n * ```ts\n * // The employee with the lowest salary\n * db.select({ value: min(employees.salary) }).from(employees)\n * ```\n */\nexport function min<T extends SQLWrapper>(expression: T): SQL<(T extends AnyColumn ? T['_']['data'] : string) | null> {\n return sql`min(${expression})`.mapWith(is(expression, Column) ? expression : String) as any;\n}\n"],"mappings":"AAAA,SAAS,UAAU;AACnB,SAAmB,WAA4B;AAC/C,SAAyB,cAAc;AAgBhC,SAAS,MAAM,YAAsC;AAC1D,SAAO,YAAY,cAAc,IAAI,IAAI,GAAG,CAAC,IAAI,QAAQ,MAAM;AACjE;AAcO,SAAS,cAAc,YAAqC;AACjE,SAAO,qBAAqB,UAAU,IAAI,QAAQ,MAAM;AAC1D;AAcO,SAAS,IAAI,YAA4C;AAC9D,SAAO,UAAU,UAAU,IAAI,QAAQ,MAAM;AAC/C;AAcO,SAAS,YAAY,YAA4C;AACtE,SAAO,mBAAmB,UAAU,IAAI,QAAQ,MAAM;AACxD;AAcO,SAAS,IAAI,YAA4C;AAC9D,SAAO,UAAU,UAAU,IAAI,QAAQ,MAAM;AAC/C;AAcO,SAAS,YAAY,YAA4C;AACtE,SAAO,mBAAmB,UAAU,IAAI,QAAQ,MAAM;AACxD;AAYO,SAAS,IAA0B,YAA4E;AACpH,SAAO,UAAU,UAAU,IAAI,QAAQ,GAAG,YAAY,MAAM,IAAI,aAAa,MAAM;AACrF;AAYO,SAAS,IAA0B,YAA4E;AACpH,SAAO,UAAU,UAAU,IAAI,QAAQ,GAAG,YAAY,MAAM,IAAI,aAAa,MAAM;AACrF;","names":[]}
@@ -1,23 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __copyProps = (to, from, except, desc) => {
7
- if (from && typeof from === "object" || typeof from === "function") {
8
- for (let key of __getOwnPropNames(from))
9
- if (!__hasOwnProp.call(to, key) && key !== except)
10
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
- }
12
- return to;
13
- };
14
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
- var functions_exports = {};
17
- module.exports = __toCommonJS(functions_exports);
18
- __reExport(functions_exports, require("./aggregate.cjs"), module.exports);
19
- // Annotate the CommonJS export names for ESM import in node:
20
- 0 && (module.exports = {
21
- ...require("./aggregate.cjs")
22
- });
23
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/sql/functions/index.ts"],"sourcesContent":["export * from './aggregate.ts';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,8BAAc,2BAAd;","names":[]}
@@ -1 +0,0 @@
1
- export * from "./aggregate.cjs";
@@ -1 +0,0 @@
1
- export * from "./aggregate.js";
@@ -1,2 +0,0 @@
1
- export * from "./aggregate.js";
2
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/sql/functions/index.ts"],"sourcesContent":["export * from './aggregate.ts';\n"],"mappings":"AAAA,cAAc;","names":[]}