rado 1.2.0 → 1.2.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/README.md +2 -2
- package/dist/core/Column.d.ts +14 -5
- package/dist/core/Column.js +19 -6
- package/dist/universal/columns.js +34 -18
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -27,7 +27,7 @@ import {connect} from 'rado/driver/pg'
|
|
|
27
27
|
import {Pool} from 'pg'
|
|
28
28
|
|
|
29
29
|
// Define your schema
|
|
30
|
-
const User = table({
|
|
30
|
+
const User = table("user", {
|
|
31
31
|
id: integer().primaryKey(),
|
|
32
32
|
name: text().notNull(),
|
|
33
33
|
email: text().unique()
|
|
@@ -165,7 +165,7 @@ Rado provides first-class support for JSON columns:
|
|
|
165
165
|
```typescript
|
|
166
166
|
import {pgTable, serial, text, jsonb} from 'rado/postgres'
|
|
167
167
|
|
|
168
|
-
const User = pgTable({
|
|
168
|
+
const User = pgTable("user", {
|
|
169
169
|
id: serial().primaryKey(),
|
|
170
170
|
name: text(),
|
|
171
171
|
metadata: jsonb<{subscribed: boolean}>()
|
package/dist/core/Column.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { DriverSpecs } from './Driver.js';
|
|
2
|
-
import { internalData } from './Internal.js';
|
|
2
|
+
import { type HasSql, internalData, internalSql } from './Internal.js';
|
|
3
3
|
import { type Sql } from './Sql.js';
|
|
4
4
|
import type { Field, FieldData } from './expr/Field.js';
|
|
5
5
|
import { type Input } from './expr/Input.js';
|
|
6
|
-
export interface
|
|
7
|
-
type:
|
|
6
|
+
export interface BaseColumnData {
|
|
7
|
+
type: HasSql;
|
|
8
8
|
name?: string;
|
|
9
9
|
json?: boolean;
|
|
10
10
|
primary?: boolean;
|
|
@@ -18,6 +18,15 @@ export interface ColumnData {
|
|
|
18
18
|
$default?(): Sql;
|
|
19
19
|
$onUpdate?(): Sql;
|
|
20
20
|
}
|
|
21
|
+
export interface ColumnData extends BaseColumnData {
|
|
22
|
+
type: ColumnType;
|
|
23
|
+
}
|
|
24
|
+
export declare class ColumnType implements HasSql {
|
|
25
|
+
kind: string;
|
|
26
|
+
args: Array<Input<unknown>>;
|
|
27
|
+
[internalSql]: Sql;
|
|
28
|
+
constructor(kind: string, args: Array<Input<unknown>>, sql?: Sql);
|
|
29
|
+
}
|
|
21
30
|
type WithoutNull<Value> = Exclude<Value, null>;
|
|
22
31
|
export declare class Column<Value = unknown> {
|
|
23
32
|
readonly [internalData]: ColumnData;
|
|
@@ -46,7 +55,7 @@ export interface RequiredColumn<Value = unknown> extends Column<WithoutNull<Valu
|
|
|
46
55
|
}
|
|
47
56
|
export interface Columns {
|
|
48
57
|
<T>(data: ColumnData): Column<T>;
|
|
49
|
-
[key: string]: (...args: Array<Input<any>>) =>
|
|
58
|
+
[key: string]: (...args: Array<Input<any>>) => ColumnType;
|
|
50
59
|
}
|
|
51
60
|
export declare const column: Columns;
|
|
52
61
|
export type ColumnArguments<Options> = [name?: string] | [options: Options] | [name: string, options: Options];
|
|
@@ -54,5 +63,5 @@ export declare function columnConfig<Options>(args: ColumnArguments<Options>): {
|
|
|
54
63
|
name: string | undefined;
|
|
55
64
|
options: Options | undefined;
|
|
56
65
|
};
|
|
57
|
-
export declare function formatColumn(column:
|
|
66
|
+
export declare function formatColumn(column: BaseColumnData): Sql;
|
|
58
67
|
export {};
|
package/dist/core/Column.js
CHANGED
|
@@ -1,8 +1,24 @@
|
|
|
1
1
|
// src/core/Column.ts
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
getData,
|
|
4
|
+
getField,
|
|
5
|
+
internalData,
|
|
6
|
+
internalSql
|
|
7
|
+
} from "./Internal.js";
|
|
3
8
|
import { sql } from "./Sql.js";
|
|
4
9
|
import { callFunction } from "./expr/Functions.js";
|
|
5
10
|
import { input, mapToColumn } from "./expr/Input.js";
|
|
11
|
+
function formatType(kind, args) {
|
|
12
|
+
return args.length === 0 ? sql.unsafe(kind) : sql`${sql.unsafe(kind)}(${sql.join(args.map(sql.inline), sql`, `)})`;
|
|
13
|
+
}
|
|
14
|
+
var ColumnType = class {
|
|
15
|
+
constructor(kind, args, sql2 = formatType(kind, args)) {
|
|
16
|
+
this.kind = kind;
|
|
17
|
+
this.args = args;
|
|
18
|
+
this[internalSql] = sql2;
|
|
19
|
+
}
|
|
20
|
+
[internalSql];
|
|
21
|
+
};
|
|
6
22
|
var Column = class _Column {
|
|
7
23
|
[internalData];
|
|
8
24
|
constructor(data) {
|
|
@@ -78,11 +94,7 @@ var column = new Proxy(createColumn, {
|
|
|
78
94
|
while (args.length > 0)
|
|
79
95
|
if (args.at(-1) === void 0) args.pop();
|
|
80
96
|
else break;
|
|
81
|
-
|
|
82
|
-
return sql`${sql.unsafe(method)}(${sql.join(
|
|
83
|
-
args.map(sql.inline),
|
|
84
|
-
sql`, `
|
|
85
|
-
)})`;
|
|
97
|
+
return new ColumnType(method, args);
|
|
86
98
|
};
|
|
87
99
|
}
|
|
88
100
|
});
|
|
@@ -113,6 +125,7 @@ function formatColumn(column2) {
|
|
|
113
125
|
}
|
|
114
126
|
export {
|
|
115
127
|
Column,
|
|
128
|
+
ColumnType,
|
|
116
129
|
JsonColumn,
|
|
117
130
|
column,
|
|
118
131
|
columnConfig,
|
|
@@ -1,23 +1,39 @@
|
|
|
1
1
|
// src/universal/columns.ts
|
|
2
|
-
import { JsonColumn, column } from "../core/Column.js";
|
|
2
|
+
import { ColumnType, JsonColumn, column } from "../core/Column.js";
|
|
3
3
|
import { sql } from "../core/Sql.js";
|
|
4
|
-
var idType =
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
4
|
+
var idType = new ColumnType(
|
|
5
|
+
"id",
|
|
6
|
+
[],
|
|
7
|
+
sql.universal({
|
|
8
|
+
sqlite: sql`integer`,
|
|
9
|
+
postgres: sql`integer generated always as identity`,
|
|
10
|
+
mysql: sql`int not null auto_increment`
|
|
11
|
+
})
|
|
12
|
+
);
|
|
13
|
+
var blobType = new ColumnType(
|
|
14
|
+
"blob",
|
|
15
|
+
[],
|
|
16
|
+
sql.universal({
|
|
17
|
+
postgres: sql`bytea`,
|
|
18
|
+
default: sql`blob`
|
|
19
|
+
})
|
|
20
|
+
);
|
|
21
|
+
var numberType = new ColumnType(
|
|
22
|
+
"number",
|
|
23
|
+
[],
|
|
24
|
+
sql.universal({
|
|
25
|
+
mysql: sql`double`,
|
|
26
|
+
default: sql`numeric`
|
|
27
|
+
})
|
|
28
|
+
);
|
|
29
|
+
var jsonbType = new ColumnType(
|
|
30
|
+
"json",
|
|
31
|
+
[],
|
|
32
|
+
sql.universal({
|
|
33
|
+
mysql: sql`json`,
|
|
34
|
+
default: sql`jsonb`
|
|
35
|
+
})
|
|
36
|
+
);
|
|
21
37
|
function id(name) {
|
|
22
38
|
return column({
|
|
23
39
|
name,
|