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.
Files changed (122) hide show
  1. package/dist/index.d.ts +3630 -0
  2. package/dist/index.esm.js +4587 -0
  3. package/dist/index.esm.js.map +1 -0
  4. package/dist/index.js +4691 -0
  5. package/dist/index.js.map +1 -0
  6. package/package.json +59 -0
  7. package/rollup.config.js +35 -0
  8. package/src/adapter.test.ts +10 -0
  9. package/src/adapter.ts +171 -0
  10. package/src/columnSchema/array.ts +21 -0
  11. package/src/columnSchema/boolean.ts +10 -0
  12. package/src/columnSchema/columnType.test.ts +129 -0
  13. package/src/columnSchema/columnType.ts +77 -0
  14. package/src/columnSchema/columnTypes.ts +145 -0
  15. package/src/columnSchema/columnsSchema.test.ts +32 -0
  16. package/src/columnSchema/columnsSchema.ts +100 -0
  17. package/src/columnSchema/commonMethods.ts +130 -0
  18. package/src/columnSchema/dateTime.ts +104 -0
  19. package/src/columnSchema/enum.ts +13 -0
  20. package/src/columnSchema/index.ts +11 -0
  21. package/src/columnSchema/json/array.ts +55 -0
  22. package/src/columnSchema/json/discriminatedUnion.ts +91 -0
  23. package/src/columnSchema/json/enum.ts +29 -0
  24. package/src/columnSchema/json/instanceOf.ts +16 -0
  25. package/src/columnSchema/json/intersection.ts +23 -0
  26. package/src/columnSchema/json/lazy.ts +22 -0
  27. package/src/columnSchema/json/literal.ts +12 -0
  28. package/src/columnSchema/json/map.ts +29 -0
  29. package/src/columnSchema/json/nativeEnum.ts +30 -0
  30. package/src/columnSchema/json/nullable.ts +33 -0
  31. package/src/columnSchema/json/nullish.ts +30 -0
  32. package/src/columnSchema/json/object.ts +206 -0
  33. package/src/columnSchema/json/optional.ts +28 -0
  34. package/src/columnSchema/json/record.ts +40 -0
  35. package/src/columnSchema/json/scalarTypes.ts +117 -0
  36. package/src/columnSchema/json/set.ts +34 -0
  37. package/src/columnSchema/json/tuple.ts +40 -0
  38. package/src/columnSchema/json/typeBase.ts +202 -0
  39. package/src/columnSchema/json/union.ts +16 -0
  40. package/src/columnSchema/json.ts +64 -0
  41. package/src/columnSchema/number.ts +122 -0
  42. package/src/columnSchema/string.ts +222 -0
  43. package/src/columnSchema/utils.ts +27 -0
  44. package/src/common.ts +86 -0
  45. package/src/db.test.ts +67 -0
  46. package/src/db.ts +212 -0
  47. package/src/errors.ts +7 -0
  48. package/src/index.ts +18 -0
  49. package/src/operators.test.ts +608 -0
  50. package/src/operators.ts +177 -0
  51. package/src/query.ts +292 -0
  52. package/src/queryDataUtils.ts +50 -0
  53. package/src/queryMethods/aggregate.test.ts +583 -0
  54. package/src/queryMethods/aggregate.ts +878 -0
  55. package/src/queryMethods/callbacks.test.ts +69 -0
  56. package/src/queryMethods/callbacks.ts +55 -0
  57. package/src/queryMethods/clear.test.ts +64 -0
  58. package/src/queryMethods/clear.ts +58 -0
  59. package/src/queryMethods/columnInfo.test.ts +45 -0
  60. package/src/queryMethods/columnInfo.ts +67 -0
  61. package/src/queryMethods/delete.test.ts +135 -0
  62. package/src/queryMethods/delete.ts +50 -0
  63. package/src/queryMethods/for.test.ts +57 -0
  64. package/src/queryMethods/for.ts +99 -0
  65. package/src/queryMethods/from.test.ts +66 -0
  66. package/src/queryMethods/from.ts +58 -0
  67. package/src/queryMethods/get.test.ts +66 -0
  68. package/src/queryMethods/get.ts +88 -0
  69. package/src/queryMethods/having.test.ts +247 -0
  70. package/src/queryMethods/having.ts +99 -0
  71. package/src/queryMethods/insert.test.ts +555 -0
  72. package/src/queryMethods/insert.ts +453 -0
  73. package/src/queryMethods/join.test.ts +150 -0
  74. package/src/queryMethods/join.ts +508 -0
  75. package/src/queryMethods/json.test.ts +398 -0
  76. package/src/queryMethods/json.ts +259 -0
  77. package/src/queryMethods/log.test.ts +172 -0
  78. package/src/queryMethods/log.ts +123 -0
  79. package/src/queryMethods/queryMethods.test.ts +629 -0
  80. package/src/queryMethods/queryMethods.ts +428 -0
  81. package/src/queryMethods/select.test.ts +479 -0
  82. package/src/queryMethods/select.ts +249 -0
  83. package/src/queryMethods/then.ts +236 -0
  84. package/src/queryMethods/transaction.test.ts +66 -0
  85. package/src/queryMethods/transaction.ts +66 -0
  86. package/src/queryMethods/union.test.ts +59 -0
  87. package/src/queryMethods/union.ts +89 -0
  88. package/src/queryMethods/update.test.ts +417 -0
  89. package/src/queryMethods/update.ts +350 -0
  90. package/src/queryMethods/upsert.test.ts +56 -0
  91. package/src/queryMethods/upsert.ts +43 -0
  92. package/src/queryMethods/where.test.ts +1594 -0
  93. package/src/queryMethods/where.ts +450 -0
  94. package/src/queryMethods/window.test.ts +66 -0
  95. package/src/queryMethods/window.ts +108 -0
  96. package/src/queryMethods/with.test.ts +191 -0
  97. package/src/queryMethods/with.ts +92 -0
  98. package/src/quote.ts +36 -0
  99. package/src/relations.ts +194 -0
  100. package/src/sql/aggregate.ts +80 -0
  101. package/src/sql/columnInfo.ts +22 -0
  102. package/src/sql/common.ts +42 -0
  103. package/src/sql/delete.ts +41 -0
  104. package/src/sql/distinct.ts +19 -0
  105. package/src/sql/fromAndAs.ts +51 -0
  106. package/src/sql/having.ts +140 -0
  107. package/src/sql/index.ts +2 -0
  108. package/src/sql/insert.ts +102 -0
  109. package/src/sql/join.ts +242 -0
  110. package/src/sql/orderBy.ts +41 -0
  111. package/src/sql/select.ts +153 -0
  112. package/src/sql/toSql.ts +153 -0
  113. package/src/sql/truncate.ts +13 -0
  114. package/src/sql/types.ts +355 -0
  115. package/src/sql/update.ts +62 -0
  116. package/src/sql/where.ts +314 -0
  117. package/src/sql/window.ts +38 -0
  118. package/src/sql/with.ts +32 -0
  119. package/src/test-utils.ts +172 -0
  120. package/src/utils.ts +140 -0
  121. package/tsconfig.build.json +6 -0
  122. 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 = () => {};
@@ -0,0 +1,6 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "exclude": [
4
+ "src/**/*.test.ts"
5
+ ]
6
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "include": ["./src"],
4
+ "compilerOptions": {
5
+ "outDir": "./dist",
6
+ "noEmit": false
7
+ }
8
+ }