prisma-sql 1.53.0 → 1.55.0

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.d.mts CHANGED
@@ -59,6 +59,49 @@ interface PrismaQueryArgs {
59
59
  method?: string;
60
60
  }
61
61
 
62
+ interface BatchQuery {
63
+ model: string;
64
+ method: PrismaMethod;
65
+ args?: Record<string, unknown>;
66
+ }
67
+ interface BatchCountQuery {
68
+ model: string;
69
+ method: 'count';
70
+ args?: {
71
+ where?: Record<string, unknown>;
72
+ };
73
+ }
74
+ interface BatchResult {
75
+ sql: string;
76
+ params: unknown[];
77
+ }
78
+ declare function buildBatchSql(queries: Record<string, BatchQuery>, modelMap: Map<string, Model>, models: Model[], dialect: SqlDialect): BatchResult & {
79
+ keys: string[];
80
+ };
81
+ declare function buildBatchCountSql(queries: BatchCountQuery[], modelMap: Map<string, Model>, models: Model[], dialect: SqlDialect): BatchResult;
82
+ declare function parseBatchCountResults(row: Record<string, unknown>, count: number): number[];
83
+ declare function parseBatchResults(row: Record<string, unknown>, keys: string[], queries: Record<string, BatchQuery>): Record<string, unknown>;
84
+
85
+ interface TransactionQuery {
86
+ model: string;
87
+ method: PrismaMethod;
88
+ args?: Record<string, unknown>;
89
+ }
90
+ interface TransactionOptions {
91
+ isolationLevel?: 'ReadCommitted' | 'RepeatableRead' | 'Serializable';
92
+ timeout?: number;
93
+ }
94
+ interface TransactionExecutor {
95
+ execute(queries: TransactionQuery[], options?: TransactionOptions): Promise<unknown[]>;
96
+ }
97
+ declare function createTransactionExecutor(deps: {
98
+ modelMap: Map<string, Model>;
99
+ allModels: Model[];
100
+ dialect: SqlDialect;
101
+ executeRaw: (sql: string, params?: unknown[]) => Promise<unknown[]>;
102
+ postgresClient?: any;
103
+ }): TransactionExecutor;
104
+
62
105
  interface SqlResult {
63
106
  sql: string;
64
107
  params: unknown[];
@@ -79,48 +122,32 @@ interface QueryInfo {
79
122
  params: unknown[];
80
123
  duration: number;
81
124
  }
125
+ interface DeferredQueryLike {
126
+ readonly model: string;
127
+ readonly method: PrismaMethod;
128
+ readonly args: any;
129
+ }
130
+ interface BatchProxy {
131
+ [modelName: string]: {
132
+ findMany: (args?: any) => DeferredQueryLike;
133
+ findFirst: (args?: any) => DeferredQueryLike;
134
+ findUnique: (args?: any) => DeferredQueryLike;
135
+ count: (args?: any) => DeferredQueryLike;
136
+ aggregate: (args?: any) => DeferredQueryLike;
137
+ groupBy: (args?: any) => DeferredQueryLike;
138
+ };
139
+ }
140
+ interface SpeedExtensionClient {
141
+ $original: any;
142
+ $batch: <T extends Record<string, DeferredQueryLike>>(callback: (batch: BatchProxy) => T | Promise<T>) => Promise<{
143
+ [K in keyof T]: any;
144
+ }>;
145
+ $transaction: (queries: TransactionQuery[], options?: TransactionOptions) => Promise<unknown[]>;
146
+ }
147
+ type ExtendedPrismaClient<T> = T & SpeedExtensionClient;
82
148
  declare function buildSQL(model: Model$1, models: Model$1[], method: PrismaMethod, args: Record<string, unknown>, dialect: SqlDialect): SqlResult;
83
- /**
84
- * Runtime-only Prisma extension for SQL acceleration.
85
- *
86
- * ⚠️ RECOMMENDED: Use generated extension instead for zero overhead!
87
- *
88
- * @example
89
- * // RECOMMENDED: Generated extension (no models/dmmf needed)
90
- * import { speedExtension } from './generated/sql'
91
- * const prisma = new PrismaClient().$extends(
92
- * speedExtension({ postgres: sql })
93
- * )
94
- *
95
- * @example
96
- * // Runtime with pre-converted models
97
- * import { speedExtension } from 'prisma-sql'
98
- * import { MODELS } from './generated/sql'
99
- * const prisma = new PrismaClient().$extends(
100
- * speedExtension({ postgres: sql, models: MODELS })
101
- * )
102
- *
103
- * @example
104
- * // Runtime with DMMF (auto-converts on startup)
105
- * import { speedExtension } from 'prisma-sql'
106
- * import { Prisma } from '@prisma/client'
107
- * const prisma = new PrismaClient().$extends(
108
- * speedExtension({ postgres: sql, dmmf: Prisma.dmmf })
109
- * )
110
- */
111
149
  declare function speedExtension(config: SpeedExtensionConfig): (prisma: any) => any;
112
- /**
113
- * Create a SQL generator function from models.
114
- *
115
- * @example
116
- * import { createToSQL } from 'prisma-sql'
117
- * import { MODELS } from './generated/sql'
118
- *
119
- * const toSQL = createToSQL(MODELS, 'postgres')
120
- * const { sql, params } = toSQL('User', 'findMany', {
121
- * where: { status: 'ACTIVE' }
122
- * })
123
- */
150
+ declare function extendPrisma<T>(prisma: T, config: SpeedExtensionConfig): ExtendedPrismaClient<T>;
124
151
  declare function createToSQL(modelsOrDmmf: Model$1[] | DMMF.Document, dialect: SqlDialect): (model: string, method: PrismaMethod, args?: Record<string, unknown>) => SqlResult;
125
152
  interface PrismaSQLConfig<TClient> {
126
153
  client: TClient;
@@ -129,31 +156,15 @@ interface PrismaSQLConfig<TClient> {
129
156
  dialect: SqlDialect;
130
157
  execute: (client: TClient, sql: string, params: unknown[]) => Promise<unknown[]>;
131
158
  }
132
- /**
133
- * Create a Prisma SQL client for environments where extensions aren't supported.
134
- *
135
- * @example
136
- * import { createPrismaSQL } from 'prisma-sql'
137
- * import { MODELS } from './generated/sql'
138
- *
139
- * const prismaSQL = createPrismaSQL({
140
- * client: sql,
141
- * models: MODELS,
142
- * dialect: 'postgres',
143
- * execute: (client, sql, params) => client.unsafe(sql, params)
144
- * })
145
- *
146
- * const users = await prismaSQL.query('User', 'findMany', {
147
- * where: { status: 'ACTIVE' }
148
- * })
149
- */
150
- declare function createPrismaSQL<TClient>(config: PrismaSQLConfig<TClient>): {
159
+ interface PrismaSQLResult<TClient> {
151
160
  toSQL: (model: string, method: PrismaMethod, args?: Record<string, unknown>) => SqlResult;
152
161
  query: <T = unknown[]>(model: string, method: PrismaMethod, args?: Record<string, unknown>) => Promise<T>;
162
+ batchSql: (queries: Record<string, BatchQuery>) => SqlResult;
153
163
  client: TClient;
154
- };
164
+ }
165
+ declare function createPrismaSQL<TClient>(config: PrismaSQLConfig<TClient>): PrismaSQLResult<TClient>;
155
166
  declare function generateSQL(directive: DirectiveProps): SQLDirective;
156
167
  declare function generateAllSQL(directives: DirectiveProps[]): SQLDirective[];
157
168
  declare function generateSQLByModel(directives: DirectiveProps[]): Map<string, SQLDirective[]>;
158
169
 
159
- export { type Field, type Model, type PrismaMethod, type PrismaQueryArgs, type PrismaSQLConfig, type QueryInfo, type SQLDirective, type SpeedExtensionConfig, type SqlDialect, type SqlResult, buildSQL, createPrismaSQL, createToSQL, generateAllSQL, generateSQL, generateSQLByModel, getGlobalDialect, setGlobalDialect, speedExtension, transformQueryResults };
170
+ export { type BatchCountQuery, type BatchProxy, type BatchQuery, type DeferredQueryLike, type ExtendedPrismaClient, type Field, type Model, type PrismaMethod, type PrismaQueryArgs, type PrismaSQLConfig, type PrismaSQLResult, type QueryInfo, type SQLDirective, type SpeedExtensionClient, type SpeedExtensionConfig, type SqlDialect, type SqlResult, type TransactionExecutor, type TransactionOptions, type TransactionQuery, buildBatchCountSql, buildBatchSql, buildSQL, createPrismaSQL, createToSQL, createTransactionExecutor, extendPrisma, generateAllSQL, generateSQL, generateSQLByModel, getGlobalDialect, parseBatchCountResults, parseBatchResults, setGlobalDialect, speedExtension, transformQueryResults };
package/dist/index.d.ts CHANGED
@@ -59,6 +59,49 @@ interface PrismaQueryArgs {
59
59
  method?: string;
60
60
  }
61
61
 
62
+ interface BatchQuery {
63
+ model: string;
64
+ method: PrismaMethod;
65
+ args?: Record<string, unknown>;
66
+ }
67
+ interface BatchCountQuery {
68
+ model: string;
69
+ method: 'count';
70
+ args?: {
71
+ where?: Record<string, unknown>;
72
+ };
73
+ }
74
+ interface BatchResult {
75
+ sql: string;
76
+ params: unknown[];
77
+ }
78
+ declare function buildBatchSql(queries: Record<string, BatchQuery>, modelMap: Map<string, Model>, models: Model[], dialect: SqlDialect): BatchResult & {
79
+ keys: string[];
80
+ };
81
+ declare function buildBatchCountSql(queries: BatchCountQuery[], modelMap: Map<string, Model>, models: Model[], dialect: SqlDialect): BatchResult;
82
+ declare function parseBatchCountResults(row: Record<string, unknown>, count: number): number[];
83
+ declare function parseBatchResults(row: Record<string, unknown>, keys: string[], queries: Record<string, BatchQuery>): Record<string, unknown>;
84
+
85
+ interface TransactionQuery {
86
+ model: string;
87
+ method: PrismaMethod;
88
+ args?: Record<string, unknown>;
89
+ }
90
+ interface TransactionOptions {
91
+ isolationLevel?: 'ReadCommitted' | 'RepeatableRead' | 'Serializable';
92
+ timeout?: number;
93
+ }
94
+ interface TransactionExecutor {
95
+ execute(queries: TransactionQuery[], options?: TransactionOptions): Promise<unknown[]>;
96
+ }
97
+ declare function createTransactionExecutor(deps: {
98
+ modelMap: Map<string, Model>;
99
+ allModels: Model[];
100
+ dialect: SqlDialect;
101
+ executeRaw: (sql: string, params?: unknown[]) => Promise<unknown[]>;
102
+ postgresClient?: any;
103
+ }): TransactionExecutor;
104
+
62
105
  interface SqlResult {
63
106
  sql: string;
64
107
  params: unknown[];
@@ -79,48 +122,32 @@ interface QueryInfo {
79
122
  params: unknown[];
80
123
  duration: number;
81
124
  }
125
+ interface DeferredQueryLike {
126
+ readonly model: string;
127
+ readonly method: PrismaMethod;
128
+ readonly args: any;
129
+ }
130
+ interface BatchProxy {
131
+ [modelName: string]: {
132
+ findMany: (args?: any) => DeferredQueryLike;
133
+ findFirst: (args?: any) => DeferredQueryLike;
134
+ findUnique: (args?: any) => DeferredQueryLike;
135
+ count: (args?: any) => DeferredQueryLike;
136
+ aggregate: (args?: any) => DeferredQueryLike;
137
+ groupBy: (args?: any) => DeferredQueryLike;
138
+ };
139
+ }
140
+ interface SpeedExtensionClient {
141
+ $original: any;
142
+ $batch: <T extends Record<string, DeferredQueryLike>>(callback: (batch: BatchProxy) => T | Promise<T>) => Promise<{
143
+ [K in keyof T]: any;
144
+ }>;
145
+ $transaction: (queries: TransactionQuery[], options?: TransactionOptions) => Promise<unknown[]>;
146
+ }
147
+ type ExtendedPrismaClient<T> = T & SpeedExtensionClient;
82
148
  declare function buildSQL(model: Model$1, models: Model$1[], method: PrismaMethod, args: Record<string, unknown>, dialect: SqlDialect): SqlResult;
83
- /**
84
- * Runtime-only Prisma extension for SQL acceleration.
85
- *
86
- * ⚠️ RECOMMENDED: Use generated extension instead for zero overhead!
87
- *
88
- * @example
89
- * // RECOMMENDED: Generated extension (no models/dmmf needed)
90
- * import { speedExtension } from './generated/sql'
91
- * const prisma = new PrismaClient().$extends(
92
- * speedExtension({ postgres: sql })
93
- * )
94
- *
95
- * @example
96
- * // Runtime with pre-converted models
97
- * import { speedExtension } from 'prisma-sql'
98
- * import { MODELS } from './generated/sql'
99
- * const prisma = new PrismaClient().$extends(
100
- * speedExtension({ postgres: sql, models: MODELS })
101
- * )
102
- *
103
- * @example
104
- * // Runtime with DMMF (auto-converts on startup)
105
- * import { speedExtension } from 'prisma-sql'
106
- * import { Prisma } from '@prisma/client'
107
- * const prisma = new PrismaClient().$extends(
108
- * speedExtension({ postgres: sql, dmmf: Prisma.dmmf })
109
- * )
110
- */
111
149
  declare function speedExtension(config: SpeedExtensionConfig): (prisma: any) => any;
112
- /**
113
- * Create a SQL generator function from models.
114
- *
115
- * @example
116
- * import { createToSQL } from 'prisma-sql'
117
- * import { MODELS } from './generated/sql'
118
- *
119
- * const toSQL = createToSQL(MODELS, 'postgres')
120
- * const { sql, params } = toSQL('User', 'findMany', {
121
- * where: { status: 'ACTIVE' }
122
- * })
123
- */
150
+ declare function extendPrisma<T>(prisma: T, config: SpeedExtensionConfig): ExtendedPrismaClient<T>;
124
151
  declare function createToSQL(modelsOrDmmf: Model$1[] | DMMF.Document, dialect: SqlDialect): (model: string, method: PrismaMethod, args?: Record<string, unknown>) => SqlResult;
125
152
  interface PrismaSQLConfig<TClient> {
126
153
  client: TClient;
@@ -129,31 +156,15 @@ interface PrismaSQLConfig<TClient> {
129
156
  dialect: SqlDialect;
130
157
  execute: (client: TClient, sql: string, params: unknown[]) => Promise<unknown[]>;
131
158
  }
132
- /**
133
- * Create a Prisma SQL client for environments where extensions aren't supported.
134
- *
135
- * @example
136
- * import { createPrismaSQL } from 'prisma-sql'
137
- * import { MODELS } from './generated/sql'
138
- *
139
- * const prismaSQL = createPrismaSQL({
140
- * client: sql,
141
- * models: MODELS,
142
- * dialect: 'postgres',
143
- * execute: (client, sql, params) => client.unsafe(sql, params)
144
- * })
145
- *
146
- * const users = await prismaSQL.query('User', 'findMany', {
147
- * where: { status: 'ACTIVE' }
148
- * })
149
- */
150
- declare function createPrismaSQL<TClient>(config: PrismaSQLConfig<TClient>): {
159
+ interface PrismaSQLResult<TClient> {
151
160
  toSQL: (model: string, method: PrismaMethod, args?: Record<string, unknown>) => SqlResult;
152
161
  query: <T = unknown[]>(model: string, method: PrismaMethod, args?: Record<string, unknown>) => Promise<T>;
162
+ batchSql: (queries: Record<string, BatchQuery>) => SqlResult;
153
163
  client: TClient;
154
- };
164
+ }
165
+ declare function createPrismaSQL<TClient>(config: PrismaSQLConfig<TClient>): PrismaSQLResult<TClient>;
155
166
  declare function generateSQL(directive: DirectiveProps): SQLDirective;
156
167
  declare function generateAllSQL(directives: DirectiveProps[]): SQLDirective[];
157
168
  declare function generateSQLByModel(directives: DirectiveProps[]): Map<string, SQLDirective[]>;
158
169
 
159
- export { type Field, type Model, type PrismaMethod, type PrismaQueryArgs, type PrismaSQLConfig, type QueryInfo, type SQLDirective, type SpeedExtensionConfig, type SqlDialect, type SqlResult, buildSQL, createPrismaSQL, createToSQL, generateAllSQL, generateSQL, generateSQLByModel, getGlobalDialect, setGlobalDialect, speedExtension, transformQueryResults };
170
+ export { type BatchCountQuery, type BatchProxy, type BatchQuery, type DeferredQueryLike, type ExtendedPrismaClient, type Field, type Model, type PrismaMethod, type PrismaQueryArgs, type PrismaSQLConfig, type PrismaSQLResult, type QueryInfo, type SQLDirective, type SpeedExtensionClient, type SpeedExtensionConfig, type SqlDialect, type SqlResult, type TransactionExecutor, type TransactionOptions, type TransactionQuery, buildBatchCountSql, buildBatchSql, buildSQL, createPrismaSQL, createToSQL, createTransactionExecutor, extendPrisma, generateAllSQL, generateSQL, generateSQLByModel, getGlobalDialect, parseBatchCountResults, parseBatchResults, setGlobalDialect, speedExtension, transformQueryResults };