prisma-sql 1.1.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/LICENSE +23 -0
- package/dist/index.cjs +4640 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.mts +94 -0
- package/dist/index.d.ts +94 -0
- package/dist/index.js +4631 -0
- package/dist/index.js.map +1 -0
- package/package.json +86 -0
- package/readme.md +994 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { ParamMap, DirectiveProps } from '@dee-wan/schema-parser';
|
|
2
|
+
|
|
3
|
+
type SqlDialect = 'postgres' | 'sqlite';
|
|
4
|
+
declare function setGlobalDialect(dialect: SqlDialect): void;
|
|
5
|
+
declare function getGlobalDialect(): SqlDialect;
|
|
6
|
+
|
|
7
|
+
interface SQLDirective {
|
|
8
|
+
header: string;
|
|
9
|
+
sql: string;
|
|
10
|
+
staticParams: any[];
|
|
11
|
+
dynamicKeys: string[];
|
|
12
|
+
paramMappings: readonly ParamMap[];
|
|
13
|
+
cache: DirectiveProps['cache'];
|
|
14
|
+
originalDirective: DirectiveProps;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
type PrismaMethod = 'findMany' | 'findFirst' | 'findUnique' | 'count' | 'aggregate' | 'groupBy';
|
|
18
|
+
|
|
19
|
+
type OrderByObject = Record<string, unknown>;
|
|
20
|
+
type OrderByArray = Array<Record<string, unknown>>;
|
|
21
|
+
type OrderByType = OrderByObject | OrderByArray | string | null | undefined;
|
|
22
|
+
|
|
23
|
+
interface Field {
|
|
24
|
+
name: string;
|
|
25
|
+
type: string;
|
|
26
|
+
isRequired: boolean;
|
|
27
|
+
isRelation: boolean;
|
|
28
|
+
relatedModel?: string;
|
|
29
|
+
relationName?: string;
|
|
30
|
+
foreignKey?: string;
|
|
31
|
+
references?: string;
|
|
32
|
+
isForeignKeyLocal?: boolean;
|
|
33
|
+
}
|
|
34
|
+
interface Model {
|
|
35
|
+
name: string;
|
|
36
|
+
tableName: string;
|
|
37
|
+
fields: Field[];
|
|
38
|
+
}
|
|
39
|
+
interface PrismaQueryArgs {
|
|
40
|
+
where?: Record<string, unknown>;
|
|
41
|
+
select?: Record<string, unknown>;
|
|
42
|
+
include?: Record<string, unknown>;
|
|
43
|
+
orderBy?: OrderByType;
|
|
44
|
+
cursor?: Record<string, unknown>;
|
|
45
|
+
take?: number | string;
|
|
46
|
+
skip?: number | string;
|
|
47
|
+
distinct?: string[];
|
|
48
|
+
by?: string[];
|
|
49
|
+
having?: Record<string, unknown>;
|
|
50
|
+
_count?: unknown;
|
|
51
|
+
_sum?: unknown;
|
|
52
|
+
_avg?: unknown;
|
|
53
|
+
_min?: unknown;
|
|
54
|
+
_max?: unknown;
|
|
55
|
+
method?: string;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
interface SqlResult {
|
|
59
|
+
sql: string;
|
|
60
|
+
params: unknown[];
|
|
61
|
+
}
|
|
62
|
+
interface SpeedExtensionConfig {
|
|
63
|
+
postgres?: any;
|
|
64
|
+
sqlite?: any;
|
|
65
|
+
dmmf?: any;
|
|
66
|
+
debug?: boolean;
|
|
67
|
+
models?: string[];
|
|
68
|
+
onQuery?: (info: QueryInfo) => void;
|
|
69
|
+
}
|
|
70
|
+
interface QueryInfo {
|
|
71
|
+
model: string;
|
|
72
|
+
method: string;
|
|
73
|
+
sql: string;
|
|
74
|
+
params: unknown[];
|
|
75
|
+
duration: number;
|
|
76
|
+
}
|
|
77
|
+
declare function speedExtension(config: SpeedExtensionConfig): (prisma: any) => any;
|
|
78
|
+
declare function createToSQL(dmmf: any, dialect: SqlDialect): (model: string, method: PrismaMethod, args?: Record<string, unknown>) => SqlResult;
|
|
79
|
+
interface PrismaSQLConfig<TClient> {
|
|
80
|
+
client: TClient;
|
|
81
|
+
dmmf: any;
|
|
82
|
+
dialect: SqlDialect;
|
|
83
|
+
execute: (client: TClient, sql: string, params: unknown[]) => Promise<unknown[]>;
|
|
84
|
+
}
|
|
85
|
+
declare function createPrismaSQL<TClient>(config: PrismaSQLConfig<TClient>): {
|
|
86
|
+
toSQL: (model: string, method: PrismaMethod, args?: Record<string, unknown>) => SqlResult;
|
|
87
|
+
query: <T = unknown[]>(model: string, method: PrismaMethod, args?: Record<string, unknown>) => Promise<T>;
|
|
88
|
+
client: TClient;
|
|
89
|
+
};
|
|
90
|
+
declare function generateSQL(directive: DirectiveProps): SQLDirective;
|
|
91
|
+
declare function generateAllSQL(directives: DirectiveProps[]): SQLDirective[];
|
|
92
|
+
declare function generateSQLByModel(directives: DirectiveProps[]): Map<string, SQLDirective[]>;
|
|
93
|
+
|
|
94
|
+
export { type Field, type Model, type PrismaMethod, type PrismaQueryArgs, type PrismaSQLConfig, type QueryInfo, type SQLDirective, type SpeedExtensionConfig, type SqlDialect, type SqlResult, createPrismaSQL, createToSQL, generateAllSQL, generateSQL, generateSQLByModel, getGlobalDialect, setGlobalDialect, speedExtension };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { ParamMap, DirectiveProps } from '@dee-wan/schema-parser';
|
|
2
|
+
|
|
3
|
+
type SqlDialect = 'postgres' | 'sqlite';
|
|
4
|
+
declare function setGlobalDialect(dialect: SqlDialect): void;
|
|
5
|
+
declare function getGlobalDialect(): SqlDialect;
|
|
6
|
+
|
|
7
|
+
interface SQLDirective {
|
|
8
|
+
header: string;
|
|
9
|
+
sql: string;
|
|
10
|
+
staticParams: any[];
|
|
11
|
+
dynamicKeys: string[];
|
|
12
|
+
paramMappings: readonly ParamMap[];
|
|
13
|
+
cache: DirectiveProps['cache'];
|
|
14
|
+
originalDirective: DirectiveProps;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
type PrismaMethod = 'findMany' | 'findFirst' | 'findUnique' | 'count' | 'aggregate' | 'groupBy';
|
|
18
|
+
|
|
19
|
+
type OrderByObject = Record<string, unknown>;
|
|
20
|
+
type OrderByArray = Array<Record<string, unknown>>;
|
|
21
|
+
type OrderByType = OrderByObject | OrderByArray | string | null | undefined;
|
|
22
|
+
|
|
23
|
+
interface Field {
|
|
24
|
+
name: string;
|
|
25
|
+
type: string;
|
|
26
|
+
isRequired: boolean;
|
|
27
|
+
isRelation: boolean;
|
|
28
|
+
relatedModel?: string;
|
|
29
|
+
relationName?: string;
|
|
30
|
+
foreignKey?: string;
|
|
31
|
+
references?: string;
|
|
32
|
+
isForeignKeyLocal?: boolean;
|
|
33
|
+
}
|
|
34
|
+
interface Model {
|
|
35
|
+
name: string;
|
|
36
|
+
tableName: string;
|
|
37
|
+
fields: Field[];
|
|
38
|
+
}
|
|
39
|
+
interface PrismaQueryArgs {
|
|
40
|
+
where?: Record<string, unknown>;
|
|
41
|
+
select?: Record<string, unknown>;
|
|
42
|
+
include?: Record<string, unknown>;
|
|
43
|
+
orderBy?: OrderByType;
|
|
44
|
+
cursor?: Record<string, unknown>;
|
|
45
|
+
take?: number | string;
|
|
46
|
+
skip?: number | string;
|
|
47
|
+
distinct?: string[];
|
|
48
|
+
by?: string[];
|
|
49
|
+
having?: Record<string, unknown>;
|
|
50
|
+
_count?: unknown;
|
|
51
|
+
_sum?: unknown;
|
|
52
|
+
_avg?: unknown;
|
|
53
|
+
_min?: unknown;
|
|
54
|
+
_max?: unknown;
|
|
55
|
+
method?: string;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
interface SqlResult {
|
|
59
|
+
sql: string;
|
|
60
|
+
params: unknown[];
|
|
61
|
+
}
|
|
62
|
+
interface SpeedExtensionConfig {
|
|
63
|
+
postgres?: any;
|
|
64
|
+
sqlite?: any;
|
|
65
|
+
dmmf?: any;
|
|
66
|
+
debug?: boolean;
|
|
67
|
+
models?: string[];
|
|
68
|
+
onQuery?: (info: QueryInfo) => void;
|
|
69
|
+
}
|
|
70
|
+
interface QueryInfo {
|
|
71
|
+
model: string;
|
|
72
|
+
method: string;
|
|
73
|
+
sql: string;
|
|
74
|
+
params: unknown[];
|
|
75
|
+
duration: number;
|
|
76
|
+
}
|
|
77
|
+
declare function speedExtension(config: SpeedExtensionConfig): (prisma: any) => any;
|
|
78
|
+
declare function createToSQL(dmmf: any, dialect: SqlDialect): (model: string, method: PrismaMethod, args?: Record<string, unknown>) => SqlResult;
|
|
79
|
+
interface PrismaSQLConfig<TClient> {
|
|
80
|
+
client: TClient;
|
|
81
|
+
dmmf: any;
|
|
82
|
+
dialect: SqlDialect;
|
|
83
|
+
execute: (client: TClient, sql: string, params: unknown[]) => Promise<unknown[]>;
|
|
84
|
+
}
|
|
85
|
+
declare function createPrismaSQL<TClient>(config: PrismaSQLConfig<TClient>): {
|
|
86
|
+
toSQL: (model: string, method: PrismaMethod, args?: Record<string, unknown>) => SqlResult;
|
|
87
|
+
query: <T = unknown[]>(model: string, method: PrismaMethod, args?: Record<string, unknown>) => Promise<T>;
|
|
88
|
+
client: TClient;
|
|
89
|
+
};
|
|
90
|
+
declare function generateSQL(directive: DirectiveProps): SQLDirective;
|
|
91
|
+
declare function generateAllSQL(directives: DirectiveProps[]): SQLDirective[];
|
|
92
|
+
declare function generateSQLByModel(directives: DirectiveProps[]): Map<string, SQLDirective[]>;
|
|
93
|
+
|
|
94
|
+
export { type Field, type Model, type PrismaMethod, type PrismaQueryArgs, type PrismaSQLConfig, type QueryInfo, type SQLDirective, type SpeedExtensionConfig, type SqlDialect, type SqlResult, createPrismaSQL, createToSQL, generateAllSQL, generateSQL, generateSQLByModel, getGlobalDialect, setGlobalDialect, speedExtension };
|