pqb 0.3.2 → 0.3.4
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 +1239 -1342
- package/dist/index.esm.js +482 -432
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +484 -434
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/columnSchema/columnType.test.ts +2 -1
- package/src/columnSchema/columnsSchema.ts +20 -60
- package/src/db.test.ts +1 -1
- package/src/db.ts +27 -20
- package/src/query.ts +36 -32
- package/src/queryDataUtils.ts +0 -7
- package/src/queryMethods/aggregate.ts +2 -3
- package/src/queryMethods/clear.ts +3 -4
- package/src/queryMethods/delete.ts +3 -3
- package/src/queryMethods/from.test.ts +2 -3
- package/src/queryMethods/get.ts +0 -1
- package/src/queryMethods/index.ts +1 -0
- package/src/queryMethods/insert.ts +14 -13
- package/src/queryMethods/json.ts +7 -3
- package/src/queryMethods/merge.test.ts +471 -0
- package/src/queryMethods/merge.ts +67 -0
- package/src/queryMethods/queryMethods.test.ts +14 -59
- package/src/queryMethods/queryMethods.ts +18 -33
- package/src/queryMethods/select.test.ts +4 -0
- package/src/queryMethods/select.ts +4 -2
- package/src/queryMethods/then.ts +3 -3
- package/src/queryMethods/update.ts +21 -14
- package/src/sql/fromAndAs.ts +2 -3
- package/src/sql/select.ts +1 -2
- package/src/sql/toSql.ts +4 -3
- package/src/sql/types.ts +7 -3
- package/src/sql/window.ts +1 -1
- package/src/sql/with.ts +25 -20
- package/src/utils.test.ts +0 -18
- package/src/utils.ts +0 -40
- package/src/columnSchema/columnsSchema.test.ts +0 -32
package/src/utils.test.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { assertType } from './test-utils';
|
|
2
2
|
import {
|
|
3
|
-
GetTypeOrRaw,
|
|
4
|
-
GetTypesOrRaw,
|
|
5
3
|
makeRegexToFindInSql,
|
|
6
4
|
MaybeArray,
|
|
7
5
|
pushOrNewArray,
|
|
@@ -9,7 +7,6 @@ import {
|
|
|
9
7
|
SetOptional,
|
|
10
8
|
SomeIsTrue,
|
|
11
9
|
} from './utils';
|
|
12
|
-
import { RawExpression } from './common';
|
|
13
10
|
|
|
14
11
|
describe('utils', () => {
|
|
15
12
|
describe('SomeIsTrue', () => {
|
|
@@ -45,21 +42,6 @@ describe('utils', () => {
|
|
|
45
42
|
});
|
|
46
43
|
});
|
|
47
44
|
|
|
48
|
-
describe('GetTypesOrRaw', () => {
|
|
49
|
-
it('should add each element to union with RawExpression', () => {
|
|
50
|
-
assertType<
|
|
51
|
-
GetTypesOrRaw<[number, string]>,
|
|
52
|
-
[number | RawExpression, string | RawExpression]
|
|
53
|
-
>();
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
describe('GetTypeOrRaw', () => {
|
|
58
|
-
it('should add type to union with RawExpression', () => {
|
|
59
|
-
assertType<GetTypeOrRaw<number>, number | RawExpression>();
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
|
|
63
45
|
describe('makeRegexToFindWordInSql', () => {
|
|
64
46
|
it('should return a proper regex', () => {
|
|
65
47
|
const regex = makeRegexToFindInSql('\\bupdatedAt\\b');
|
package/src/utils.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { RawExpression } from './common';
|
|
2
1
|
import { QueryData, toSqlCacheKey } from './sql';
|
|
3
2
|
|
|
4
3
|
export type SomeIsTrue<T extends unknown[]> = T extends [
|
|
@@ -16,46 +15,7 @@ export type SetOptional<T, K extends PropertyKey> = Omit<T, K> & {
|
|
|
16
15
|
[P in K]?: P extends keyof T ? T[P] : never;
|
|
17
16
|
};
|
|
18
17
|
|
|
19
|
-
export type GetTypesOrRaw<T extends [...unknown[]]> = T extends [
|
|
20
|
-
infer Head,
|
|
21
|
-
...infer Tail,
|
|
22
|
-
]
|
|
23
|
-
? [GetTypeOrRaw<Head>, ...GetTypesOrRaw<Tail>]
|
|
24
|
-
: [];
|
|
25
|
-
|
|
26
|
-
export type GetTypeOrRaw<T> = T | RawExpression;
|
|
27
|
-
|
|
28
|
-
// credits goes to https://stackoverflow.com/a/50375286
|
|
29
|
-
export type UnionToIntersection<U> =
|
|
30
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
31
|
-
(U extends any ? (k: U) => void : never) extends (k: infer I) => void
|
|
32
|
-
? I
|
|
33
|
-
: never;
|
|
34
|
-
|
|
35
18
|
// Converts union to overloaded function
|
|
36
|
-
export type UnionToOvlds<U> = UnionToIntersection<
|
|
37
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
38
|
-
U extends any ? (f: U) => void : never
|
|
39
|
-
>;
|
|
40
|
-
|
|
41
|
-
type PopPropertyKeyUnion<U> = UnionToOvlds<U> extends (
|
|
42
|
-
a: infer A extends PropertyKey,
|
|
43
|
-
) => void
|
|
44
|
-
? A
|
|
45
|
-
: never;
|
|
46
|
-
|
|
47
|
-
type IsUnion<T> = [T] extends [UnionToIntersection<T>] ? false : true;
|
|
48
|
-
|
|
49
|
-
export type PropertyKeyUnionToArray<
|
|
50
|
-
T,
|
|
51
|
-
A extends PropertyKey[] = [],
|
|
52
|
-
> = IsUnion<T> extends true
|
|
53
|
-
? PropertyKeyUnionToArray<
|
|
54
|
-
Exclude<T, PopPropertyKeyUnion<T>>,
|
|
55
|
-
[PopPropertyKeyUnion<T>, ...A]
|
|
56
|
-
>
|
|
57
|
-
: [T, ...A];
|
|
58
|
-
|
|
59
19
|
type OptionalPropertyNames<T> = {
|
|
60
20
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
61
21
|
[K in keyof T]-?: {} extends { [P in K]: T[K] } ? K : never;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { AssertEqual } from '../test-utils';
|
|
2
|
-
import { TableSchema } from './columnsSchema';
|
|
3
|
-
import { columnTypes } from './columnTypes';
|
|
4
|
-
|
|
5
|
-
describe('columnsSchema', () => {
|
|
6
|
-
describe('schema methods', () => {
|
|
7
|
-
const createSchema = () => {
|
|
8
|
-
return new TableSchema({
|
|
9
|
-
a: columnTypes.integer().primaryKey(),
|
|
10
|
-
b: columnTypes.decimal().primaryKey(),
|
|
11
|
-
c: columnTypes.text(),
|
|
12
|
-
});
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
describe('.primaryKeys', () => {
|
|
16
|
-
it('should be array of primary key names', () => {
|
|
17
|
-
const schema = createSchema();
|
|
18
|
-
const eq: AssertEqual<typeof schema.primaryKeys, ['a', 'b']> = true;
|
|
19
|
-
expect(eq).toBe(true);
|
|
20
|
-
expect(schema.primaryKeys).toEqual(['a', 'b']);
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
describe('.primaryTypes', () => {
|
|
25
|
-
const schema = createSchema();
|
|
26
|
-
const eq: AssertEqual<typeof schema.primaryTypes, [number, number]> =
|
|
27
|
-
true;
|
|
28
|
-
expect(eq).toBe(true);
|
|
29
|
-
expect(schema.primaryTypes).toEqual(undefined);
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
});
|