rado 0.2.34 → 0.2.36
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/README.md +2 -2
- package/dist/define/Column.d.ts +1 -1
- package/dist/define/Expr.d.ts +4 -0
- package/dist/define/Expr.js +4 -0
- package/dist/define/Fields.d.ts +10 -4
- package/dist/define/Selection.d.ts +2 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.js +8 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,8 +3,6 @@
|
|
|
3
3
|
Fully typed, lightweight TypeScript query builder.
|
|
4
4
|
Currently focused on SQLite.
|
|
5
5
|
|
|
6
|
-
<pre>npm install <a href="https://www.npmjs.com/package/rado">rado</a></pre>
|
|
7
|
-
|
|
8
6
|
- Definition via TypeScript types
|
|
9
7
|
- Composable queries
|
|
10
8
|
- Aggregate rows in selects
|
|
@@ -12,6 +10,8 @@ Currently focused on SQLite.
|
|
|
12
10
|
- No code generation step
|
|
13
11
|
- No dependencies
|
|
14
12
|
|
|
13
|
+
<pre>npm install <a href="https://www.npmjs.com/package/rado">rado</a></pre>
|
|
14
|
+
|
|
15
15
|
## Queries
|
|
16
16
|
|
|
17
17
|
#### Where
|
package/dist/define/Column.d.ts
CHANGED
|
@@ -56,7 +56,7 @@ export declare class PrimaryColumn<T, K> extends ValueColumn<string extends K ?
|
|
|
56
56
|
[Column.IsPrimary]: K;
|
|
57
57
|
}
|
|
58
58
|
export interface ObjectColumn<T> {
|
|
59
|
-
<X extends T = T>(): Column<T extends null ? X | null : X> & Fields<X>;
|
|
59
|
+
<X extends T = T>(): Column<T extends null ? X | null : X> & Fields<T extends null ? X | null : X>;
|
|
60
60
|
}
|
|
61
61
|
export declare class ObjectColumn<T> extends Callable implements Column<T> {
|
|
62
62
|
[Column.Type]: T;
|
package/dist/define/Expr.d.ts
CHANGED
|
@@ -162,12 +162,16 @@ export declare class Expr<T> {
|
|
|
162
162
|
sure(): Expr<NonNullable<T>>;
|
|
163
163
|
get<T>(name: string): Expr<T>;
|
|
164
164
|
}
|
|
165
|
+
export interface ObjectExpr {
|
|
166
|
+
[Expr.Data]: ExprData;
|
|
167
|
+
}
|
|
165
168
|
export declare namespace Expr {
|
|
166
169
|
const Data: unique symbol;
|
|
167
170
|
const IsExpr: unique symbol;
|
|
168
171
|
const ToExpr: unique symbol;
|
|
169
172
|
const NULL: Expr<null>;
|
|
170
173
|
function value<T>(value: T): Expr<T>;
|
|
174
|
+
function get<T = any>(expr: ObjectExpr, field: string): Expr<T>;
|
|
171
175
|
function create<T>(input: EV<T>): Expr<T>;
|
|
172
176
|
function and(...conditions: Array<EV<boolean>>): Expr<boolean>;
|
|
173
177
|
function or(...conditions: Array<EV<boolean>>): Expr<boolean>;
|
package/dist/define/Expr.js
CHANGED
|
@@ -396,6 +396,10 @@ class Expr {
|
|
|
396
396
|
return new Expr2(new ExprData.Param(new ParamData.Value(value2)));
|
|
397
397
|
}
|
|
398
398
|
Expr2.value = value;
|
|
399
|
+
function get(expr, field) {
|
|
400
|
+
return new Expr2(new ExprData.Field(expr[Expr2.Data], field));
|
|
401
|
+
}
|
|
402
|
+
Expr2.get = get;
|
|
399
403
|
function create(input) {
|
|
400
404
|
if (isExpr(input))
|
|
401
405
|
return input;
|
package/dist/define/Fields.d.ts
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Column } from './Column.js';
|
|
2
|
+
import { Expr, ObjectExpr } from './Expr.js';
|
|
2
3
|
type ObjectUnion<T> = {
|
|
3
4
|
[K in T extends infer P ? keyof P : never]: T extends infer P ? K extends keyof P ? P[K] : never : never;
|
|
4
5
|
};
|
|
5
|
-
type
|
|
6
|
-
|
|
6
|
+
type Expand<T> = {
|
|
7
|
+
[K in keyof T]: T[K];
|
|
8
|
+
} & {};
|
|
9
|
+
type ObjectField<T> = Expand<ObjectExpr & FieldsOf<ObjectUnion<T>>>;
|
|
7
10
|
type FieldsOf<Row> = [Row] extends [Record<string, any>] ? {
|
|
8
11
|
[K in keyof Row]-?: Field<Row[K]>;
|
|
9
12
|
} : never;
|
|
13
|
+
type Field<T> = [NonNullable<T>] extends [{
|
|
14
|
+
[Column.IsPrimary]: any;
|
|
15
|
+
}] ? Expr<T> : [NonNullable<T>] extends [Array<any>] ? Expr<T> : [NonNullable<T>] extends [object] ? ObjectField<T> : Expr<T>;
|
|
10
16
|
type IsStrictlyAny<T> = (T extends never ? true : false) extends false ? false : true;
|
|
11
|
-
export type Fields<T> = IsStrictlyAny<T> extends true ? any :
|
|
17
|
+
export type Fields<T> = IsStrictlyAny<T> extends true ? any : Field<T>;
|
|
12
18
|
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Column } from './Column.js';
|
|
1
2
|
import type { Expr } from './Expr.js';
|
|
2
3
|
import type { Select, SelectFirst } from './query/Select.js';
|
|
3
4
|
type SelectionBase = unknown | (() => any) | Expr<any> | Select<any> | SelectFirst<any>;
|
|
@@ -11,7 +12,7 @@ export declare namespace Selection {
|
|
|
11
12
|
[TableType](): infer K;
|
|
12
13
|
} ? K : T extends {
|
|
13
14
|
[CursorType](): infer K;
|
|
14
|
-
} ? K : T extends Expr<infer K> ? K : T extends Record<string, Selection> ? {
|
|
15
|
+
} ? K : T extends Expr<infer K> ? K : T extends Column<infer K> ? K : T extends Record<string, Selection> ? {
|
|
15
16
|
[K in keyof T]: Infer<T[K]>;
|
|
16
17
|
} : T extends () => any ? never : unknown extends T ? never : T;
|
|
17
18
|
type With<A, B> = Expr<Combine<A, B>>;
|
package/dist/index.d.ts
CHANGED
|
@@ -14,6 +14,14 @@ export * from './define/Sql.js';
|
|
|
14
14
|
export * from './define/Table.js';
|
|
15
15
|
export * from './define/Target.js';
|
|
16
16
|
export * from './define/VirtualTable.js';
|
|
17
|
+
export * from './define/query/Batch.js';
|
|
18
|
+
export * from './define/query/CreateTable.js';
|
|
19
|
+
export * from './define/query/Delete.js';
|
|
20
|
+
export * from './define/query/Insert.js';
|
|
21
|
+
export * from './define/query/Select.js';
|
|
22
|
+
export * from './define/query/TableSelect.js';
|
|
23
|
+
export * from './define/query/Union.js';
|
|
24
|
+
export * from './define/query/Update.js';
|
|
17
25
|
export type { Driver } from './lib/Driver.js';
|
|
18
26
|
export type { FormatContext, Formatter } from './lib/Formatter.js';
|
|
19
27
|
export type { Sanitizer } from './lib/Sanitizer.js';
|
package/dist/index.js
CHANGED
|
@@ -11,4 +11,12 @@ export * from "./define/Sql.js";
|
|
|
11
11
|
export * from "./define/Table.js";
|
|
12
12
|
export * from "./define/Target.js";
|
|
13
13
|
export * from "./define/VirtualTable.js";
|
|
14
|
+
export * from "./define/query/Batch.js";
|
|
15
|
+
export * from "./define/query/CreateTable.js";
|
|
16
|
+
export * from "./define/query/Delete.js";
|
|
17
|
+
export * from "./define/query/Insert.js";
|
|
18
|
+
export * from "./define/query/Select.js";
|
|
19
|
+
export * from "./define/query/TableSelect.js";
|
|
20
|
+
export * from "./define/query/Union.js";
|
|
21
|
+
export * from "./define/query/Update.js";
|
|
14
22
|
export * from "./lib/SqlError.js";
|