@stacksjs/database 0.70.73 → 0.70.75

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/types.d.ts CHANGED
@@ -35,6 +35,7 @@ export declare interface Sql {
35
35
  */
36
36
  export declare interface ColumnRef {
37
37
  readonly raw: string
38
+ as: (alias: string) => ColumnRef
38
39
  }
39
40
  /**
40
41
  * Fluent aggregate-function builder accessible via
@@ -59,6 +60,7 @@ export declare interface AggregateExpression {
59
60
  * genuinely needed.
60
61
  */
61
62
  export declare interface ExpressionFunctions {
63
+ countAll: () => AggregateExpression
62
64
  count: (column: string) => AggregateExpression
63
65
  sum: (column: string) => AggregateExpression
64
66
  avg: (column: string) => AggregateExpression
@@ -91,6 +93,7 @@ export declare interface ExpressionFunctions {
91
93
  * implementation in one place rather than re-typing every call site.
92
94
  */
93
95
  export declare interface StacksExpressionBuilder {
96
+ (left: unknown, op: ExpressionOperator | string, right: unknown): unknown
94
97
  or: (expressions: ReadonlyArray<unknown>) => unknown
95
98
  and?: (expressions: ReadonlyArray<unknown>) => unknown
96
99
  cmpr: (left: unknown, op: ExpressionOperator, right: unknown) => unknown
package/dist/utils.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { createQueryBuilder, setConfig } from '@stacksjs/query-builder';
2
- import type { DatabaseSchema } from '@stacksjs/query-builder';
3
2
  export declare function acquireDbConfigLock(): Promise<() => void>;
4
3
  // Function to initialize the config when it's available
5
4
  export declare function initializeDbConfig(config: any): void;
6
5
  export declare function ensureDatabaseConfigLoaded(): Promise<void>;
6
+ declare function getDb(): ReturnType<typeof createQueryBuilder>;
7
7
  /**
8
8
  * Lazy proxy for the query builder - connection is only made when first used.
9
9
  * This is the main entry point for database operations.
@@ -23,7 +23,8 @@ export declare const db: Proxy;
23
23
  * with no schema). Tests cover the runtime semantics.
24
24
  */
25
25
  export declare interface FluentChain {
26
- where: (...args: any[]) => FluentChain
26
+ where(callback: (eb: import('./types').StacksExpressionBuilder) => unknown): FluentChain
27
+ where(...args: any[]): FluentChain
27
28
  whereNull: (...args: any[]) => FluentChain
28
29
  whereNotNull: (...args: any[]) => FluentChain
29
30
  whereIn: (...args: any[]) => FluentChain
@@ -51,7 +52,8 @@ export declare interface FluentChain {
51
52
  orderBy: (...args: any[]) => FluentChain
52
53
  limit: (...args: any[]) => FluentChain
53
54
  offset: (...args: any[]) => FluentChain
54
- select: (...args: any[]) => FluentChain
55
+ select(selection: ((eb: import('./types').StacksExpressionBuilder) => unknown) | ReadonlyArray<string | ((eb: import('./types').StacksExpressionBuilder) => unknown) | unknown>): FluentChain
56
+ select(...args: any[]): FluentChain
55
57
  selectAll: () => FluentChain
56
58
  selectAllRelations: () => FluentChain
57
59
  selectRaw: (...args: any[]) => FluentChain
@@ -87,6 +89,7 @@ export declare interface FluentChain {
87
89
  max: (...args: any[]) => Promise<any>
88
90
  exists: () => Promise<boolean>
89
91
  doesntExist: () => Promise<boolean>
92
+ $call: (callback: (query: FluentChain) => FluentChain) => FluentChain
90
93
  [key: string]: any
91
94
  }
92
95
  /*.ts` and
@@ -109,9 +112,17 @@ export declare interface FluentChain {
109
112
  */
110
113
  // eslint-disable-next-line ts/no-empty-object-type
111
114
  export declare interface DatabaseSchema {}
112
- // Permissive schema type that accepts any table name with any columns
113
- // This allows the query builder to work before model types are generated
114
- declare type AnySchema = DatabaseSchema<any> & Record<string, { columns: Record<string, any>, primaryKey: string }>;
115
+ declare interface Db extends Pick<Required<RawQueryBuilder>, GenericPassthroughKeys> {
116
+ fn: import('./types').ExpressionFunctions
117
+ selectFrom: (table: TableName) => FluentChain
118
+ insertInto: (table: TableName) => FluentChain
119
+ updateTable: (table: TableName) => FluentChain
120
+ deleteFrom: (table: TableName) => FluentChain
121
+ table: (table: TableName) => FluentChain
122
+ selectFromSub: (sub: any, alias: string) => FluentChain
123
+ select: (table: TableName, ...columns: string[]) => FluentChain
124
+ unsafe: (query: string, params?: any[]) => UnsafeReturn
125
+ }
115
126
  // The bun-query-builder types `unsafe()` as returning `Promise<any>`, but at
116
127
  // runtime it returns a Bun SQL Statement that has `.execute()`. This interface
117
128
  // corrects the return type so callers can chain `.execute()` without type errors.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/database",
3
3
  "type": "module",
4
- "version": "0.70.73",
4
+ "version": "0.70.75",
5
5
  "description": "The Stacks database integration.",
6
6
  "author": "Chris Breuer",
7
7
  "contributors": [
@@ -54,18 +54,18 @@
54
54
  "prepublishOnly": "bun run build"
55
55
  },
56
56
  "dependencies": {
57
- "bun-query-builder": "^0.1.38"
57
+ "bun-query-builder": "^0.1.47"
58
58
  },
59
59
  "devDependencies": {
60
- "@stacksjs/cli": "0.70.73",
61
- "@stacksjs/config": "0.70.73",
62
- "@stacksjs/logging": "0.70.73",
63
- "@stacksjs/router": "0.70.73",
64
- "better-dx": "^0.2.12",
65
- "@stacksjs/path": "0.70.73",
66
- "@stacksjs/query-builder": "0.70.73",
67
- "@stacksjs/storage": "0.70.73",
68
- "@stacksjs/strings": "0.70.73",
69
- "@stacksjs/utils": "0.70.73"
60
+ "@stacksjs/cli": "0.70.75",
61
+ "@stacksjs/config": "0.70.75",
62
+ "@stacksjs/logging": "0.70.75",
63
+ "@stacksjs/router": "0.70.75",
64
+ "better-dx": "^0.2.16",
65
+ "@stacksjs/path": "0.70.75",
66
+ "@stacksjs/query-builder": "0.70.75",
67
+ "@stacksjs/storage": "0.70.75",
68
+ "@stacksjs/strings": "0.70.75",
69
+ "@stacksjs/utils": "0.70.75"
70
70
  }
71
71
  }