pqb 0.0.1
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.ts +3630 -0
- package/dist/index.esm.js +4587 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +4691 -0
- package/dist/index.js.map +1 -0
- package/package.json +59 -0
- package/rollup.config.js +35 -0
- package/src/adapter.test.ts +10 -0
- package/src/adapter.ts +171 -0
- package/src/columnSchema/array.ts +21 -0
- package/src/columnSchema/boolean.ts +10 -0
- package/src/columnSchema/columnType.test.ts +129 -0
- package/src/columnSchema/columnType.ts +77 -0
- package/src/columnSchema/columnTypes.ts +145 -0
- package/src/columnSchema/columnsSchema.test.ts +32 -0
- package/src/columnSchema/columnsSchema.ts +100 -0
- package/src/columnSchema/commonMethods.ts +130 -0
- package/src/columnSchema/dateTime.ts +104 -0
- package/src/columnSchema/enum.ts +13 -0
- package/src/columnSchema/index.ts +11 -0
- package/src/columnSchema/json/array.ts +55 -0
- package/src/columnSchema/json/discriminatedUnion.ts +91 -0
- package/src/columnSchema/json/enum.ts +29 -0
- package/src/columnSchema/json/instanceOf.ts +16 -0
- package/src/columnSchema/json/intersection.ts +23 -0
- package/src/columnSchema/json/lazy.ts +22 -0
- package/src/columnSchema/json/literal.ts +12 -0
- package/src/columnSchema/json/map.ts +29 -0
- package/src/columnSchema/json/nativeEnum.ts +30 -0
- package/src/columnSchema/json/nullable.ts +33 -0
- package/src/columnSchema/json/nullish.ts +30 -0
- package/src/columnSchema/json/object.ts +206 -0
- package/src/columnSchema/json/optional.ts +28 -0
- package/src/columnSchema/json/record.ts +40 -0
- package/src/columnSchema/json/scalarTypes.ts +117 -0
- package/src/columnSchema/json/set.ts +34 -0
- package/src/columnSchema/json/tuple.ts +40 -0
- package/src/columnSchema/json/typeBase.ts +202 -0
- package/src/columnSchema/json/union.ts +16 -0
- package/src/columnSchema/json.ts +64 -0
- package/src/columnSchema/number.ts +122 -0
- package/src/columnSchema/string.ts +222 -0
- package/src/columnSchema/utils.ts +27 -0
- package/src/common.ts +86 -0
- package/src/db.test.ts +67 -0
- package/src/db.ts +212 -0
- package/src/errors.ts +7 -0
- package/src/index.ts +18 -0
- package/src/operators.test.ts +608 -0
- package/src/operators.ts +177 -0
- package/src/query.ts +292 -0
- package/src/queryDataUtils.ts +50 -0
- package/src/queryMethods/aggregate.test.ts +583 -0
- package/src/queryMethods/aggregate.ts +878 -0
- package/src/queryMethods/callbacks.test.ts +69 -0
- package/src/queryMethods/callbacks.ts +55 -0
- package/src/queryMethods/clear.test.ts +64 -0
- package/src/queryMethods/clear.ts +58 -0
- package/src/queryMethods/columnInfo.test.ts +45 -0
- package/src/queryMethods/columnInfo.ts +67 -0
- package/src/queryMethods/delete.test.ts +135 -0
- package/src/queryMethods/delete.ts +50 -0
- package/src/queryMethods/for.test.ts +57 -0
- package/src/queryMethods/for.ts +99 -0
- package/src/queryMethods/from.test.ts +66 -0
- package/src/queryMethods/from.ts +58 -0
- package/src/queryMethods/get.test.ts +66 -0
- package/src/queryMethods/get.ts +88 -0
- package/src/queryMethods/having.test.ts +247 -0
- package/src/queryMethods/having.ts +99 -0
- package/src/queryMethods/insert.test.ts +555 -0
- package/src/queryMethods/insert.ts +453 -0
- package/src/queryMethods/join.test.ts +150 -0
- package/src/queryMethods/join.ts +508 -0
- package/src/queryMethods/json.test.ts +398 -0
- package/src/queryMethods/json.ts +259 -0
- package/src/queryMethods/log.test.ts +172 -0
- package/src/queryMethods/log.ts +123 -0
- package/src/queryMethods/queryMethods.test.ts +629 -0
- package/src/queryMethods/queryMethods.ts +428 -0
- package/src/queryMethods/select.test.ts +479 -0
- package/src/queryMethods/select.ts +249 -0
- package/src/queryMethods/then.ts +236 -0
- package/src/queryMethods/transaction.test.ts +66 -0
- package/src/queryMethods/transaction.ts +66 -0
- package/src/queryMethods/union.test.ts +59 -0
- package/src/queryMethods/union.ts +89 -0
- package/src/queryMethods/update.test.ts +417 -0
- package/src/queryMethods/update.ts +350 -0
- package/src/queryMethods/upsert.test.ts +56 -0
- package/src/queryMethods/upsert.ts +43 -0
- package/src/queryMethods/where.test.ts +1594 -0
- package/src/queryMethods/where.ts +450 -0
- package/src/queryMethods/window.test.ts +66 -0
- package/src/queryMethods/window.ts +108 -0
- package/src/queryMethods/with.test.ts +191 -0
- package/src/queryMethods/with.ts +92 -0
- package/src/quote.ts +36 -0
- package/src/relations.ts +194 -0
- package/src/sql/aggregate.ts +80 -0
- package/src/sql/columnInfo.ts +22 -0
- package/src/sql/common.ts +42 -0
- package/src/sql/delete.ts +41 -0
- package/src/sql/distinct.ts +19 -0
- package/src/sql/fromAndAs.ts +51 -0
- package/src/sql/having.ts +140 -0
- package/src/sql/index.ts +2 -0
- package/src/sql/insert.ts +102 -0
- package/src/sql/join.ts +242 -0
- package/src/sql/orderBy.ts +41 -0
- package/src/sql/select.ts +153 -0
- package/src/sql/toSql.ts +153 -0
- package/src/sql/truncate.ts +13 -0
- package/src/sql/types.ts +355 -0
- package/src/sql/update.ts +62 -0
- package/src/sql/where.ts +314 -0
- package/src/sql/window.ts +38 -0
- package/src/sql/with.ts +32 -0
- package/src/test-utils.ts +172 -0
- package/src/utils.ts +140 -0
- package/tsconfig.build.json +6 -0
- package/tsconfig.json +8 -0
package/src/utils.ts
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { RawExpression } from './common';
|
|
2
|
+
import { QueryData } from './sql';
|
|
3
|
+
|
|
4
|
+
export type MaybeArray<T> = T | T[];
|
|
5
|
+
|
|
6
|
+
export type SetOptional<T, K extends PropertyKey> = Omit<T, K> & {
|
|
7
|
+
[P in K]?: P extends keyof T ? T[P] : never;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export type GetTypesOrRaw<T extends [...unknown[]]> = T extends [
|
|
11
|
+
infer Head,
|
|
12
|
+
...infer Tail,
|
|
13
|
+
]
|
|
14
|
+
? [GetTypeOrRaw<Head>, ...GetTypesOrRaw<Tail>]
|
|
15
|
+
: [];
|
|
16
|
+
|
|
17
|
+
export type GetTypeOrRaw<T> = T | RawExpression;
|
|
18
|
+
|
|
19
|
+
// credits goes to https://stackoverflow.com/a/50375286
|
|
20
|
+
export type UnionToIntersection<U> =
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
22
|
+
(U extends any ? (k: U) => void : never) extends (k: infer I) => void
|
|
23
|
+
? I
|
|
24
|
+
: never;
|
|
25
|
+
|
|
26
|
+
// Converts union to overloaded function
|
|
27
|
+
export type UnionToOvlds<U> = UnionToIntersection<
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
29
|
+
U extends any ? (f: U) => void : never
|
|
30
|
+
>;
|
|
31
|
+
|
|
32
|
+
type PopPropertyKeyUnion<U> = UnionToOvlds<U> extends (
|
|
33
|
+
a: infer A extends PropertyKey,
|
|
34
|
+
) => void
|
|
35
|
+
? A
|
|
36
|
+
: never;
|
|
37
|
+
|
|
38
|
+
type IsUnion<T> = [T] extends [UnionToIntersection<T>] ? false : true;
|
|
39
|
+
|
|
40
|
+
export type PropertyKeyUnionToArray<
|
|
41
|
+
T,
|
|
42
|
+
A extends PropertyKey[] = [],
|
|
43
|
+
> = IsUnion<T> extends true
|
|
44
|
+
? PropertyKeyUnionToArray<
|
|
45
|
+
Exclude<T, PopPropertyKeyUnion<T>>,
|
|
46
|
+
[PopPropertyKeyUnion<T>, ...A]
|
|
47
|
+
>
|
|
48
|
+
: [T, ...A];
|
|
49
|
+
|
|
50
|
+
type OptionalPropertyNames<T> = {
|
|
51
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
52
|
+
[K in keyof T]-?: {} extends { [P in K]: T[K] } ? K : never;
|
|
53
|
+
}[keyof T];
|
|
54
|
+
|
|
55
|
+
type SpreadProperties<L, R, K extends keyof L & keyof R> = {
|
|
56
|
+
[P in K]: L[P] | Exclude<R[P], undefined>;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
type Id<T> = T extends infer U ? { [K in keyof U]: U[K] } : never;
|
|
60
|
+
|
|
61
|
+
type SpreadTwo<L, R> = Id<
|
|
62
|
+
Pick<L, Exclude<keyof L, keyof R>> &
|
|
63
|
+
Pick<R, Exclude<keyof R, OptionalPropertyNames<R>>> &
|
|
64
|
+
Pick<R, Exclude<OptionalPropertyNames<R>, keyof L>> &
|
|
65
|
+
SpreadProperties<L, R, OptionalPropertyNames<R> & keyof L>
|
|
66
|
+
>;
|
|
67
|
+
|
|
68
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
69
|
+
export type Spread<A extends readonly [...any]> = A extends [
|
|
70
|
+
infer L,
|
|
71
|
+
...infer R,
|
|
72
|
+
]
|
|
73
|
+
? SpreadTwo<L, Spread<R>>
|
|
74
|
+
: unknown;
|
|
75
|
+
|
|
76
|
+
export type SimpleSpread<A extends readonly [...any]> = A extends [
|
|
77
|
+
infer L,
|
|
78
|
+
...infer R,
|
|
79
|
+
]
|
|
80
|
+
? L & SimpleSpread<R>
|
|
81
|
+
: // eslint-disable-next-line @typescript-eslint/ban-types
|
|
82
|
+
{};
|
|
83
|
+
|
|
84
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
85
|
+
export type FilterTuple<T extends readonly any[], E> = T extends [
|
|
86
|
+
infer F,
|
|
87
|
+
...infer R,
|
|
88
|
+
]
|
|
89
|
+
? [F] extends [E]
|
|
90
|
+
? [F, ...FilterTuple<R, E>]
|
|
91
|
+
: FilterTuple<R, E>
|
|
92
|
+
: [];
|
|
93
|
+
|
|
94
|
+
export type CoalesceString<
|
|
95
|
+
Left extends string | undefined,
|
|
96
|
+
Right extends string,
|
|
97
|
+
> = Left extends undefined ? Right : Left;
|
|
98
|
+
|
|
99
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
100
|
+
export function applyMixins(derivedCtor: any, constructors: any[]) {
|
|
101
|
+
constructors.forEach((baseCtor) => {
|
|
102
|
+
Object.getOwnPropertyNames(baseCtor.prototype).forEach((name) => {
|
|
103
|
+
Object.defineProperty(
|
|
104
|
+
derivedCtor.prototype,
|
|
105
|
+
name,
|
|
106
|
+
Object.getOwnPropertyDescriptor(baseCtor.prototype, name) ||
|
|
107
|
+
Object.create(null),
|
|
108
|
+
);
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export const joinTruthy = (...strings: (string | false | undefined)[]) => {
|
|
114
|
+
return strings.filter((string) => string).join('');
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
export const getClonedQueryData = (query: QueryData): QueryData => {
|
|
118
|
+
const cloned = { ...query };
|
|
119
|
+
|
|
120
|
+
for (const key in query) {
|
|
121
|
+
if (Array.isArray(query[key as keyof QueryData])) {
|
|
122
|
+
(cloned as Record<string, unknown>)[key] = [
|
|
123
|
+
...(query[key as keyof QueryData] as unknown[]),
|
|
124
|
+
];
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return cloned;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
export const getQueryAs = (q: { table?: string; query: { as?: string } }) => {
|
|
132
|
+
return q.query.as || (q.table as string);
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
export const toArray = <T>(item: T) =>
|
|
136
|
+
(Array.isArray(item) ? item : [item]) as unknown as T extends unknown[]
|
|
137
|
+
? T
|
|
138
|
+
: [T];
|
|
139
|
+
|
|
140
|
+
export const noop = () => {};
|