rado 0.3.0 → 0.3.2

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 (43) hide show
  1. package/README.md +275 -275
  2. package/dist/define/Column.d.ts +14 -1
  3. package/dist/define/Column.js +25 -1
  4. package/dist/define/Cursor.d.ts +85 -0
  5. package/dist/define/Cursor.js +256 -0
  6. package/dist/define/Schema.js +8 -3
  7. package/dist/define/Update.d.ts +4 -0
  8. package/dist/define/Update.js +0 -0
  9. package/dist/lib/Column.d.ts +57 -0
  10. package/dist/lib/Column.js +68 -0
  11. package/dist/lib/Cursor.d.ts +85 -0
  12. package/dist/lib/Cursor.js +256 -0
  13. package/dist/lib/Expr.d.ts +154 -0
  14. package/dist/lib/Expr.js +284 -0
  15. package/dist/lib/Fields.d.ts +13 -0
  16. package/dist/lib/Fields.js +0 -0
  17. package/dist/lib/Formatter.d.ts +1 -1
  18. package/dist/lib/Formatter.js +19 -4
  19. package/dist/lib/Functions.d.ts +5 -0
  20. package/dist/lib/Functions.js +11 -0
  21. package/dist/lib/Id.d.ts +3 -0
  22. package/dist/lib/Id.js +0 -0
  23. package/dist/lib/Index.d.ts +17 -0
  24. package/dist/lib/Index.js +20 -0
  25. package/dist/lib/Ops.d.ts +7 -0
  26. package/dist/lib/Ops.js +36 -0
  27. package/dist/lib/OrderBy.d.ts +9 -0
  28. package/dist/lib/OrderBy.js +9 -0
  29. package/dist/lib/Param.d.ts +20 -0
  30. package/dist/lib/Param.js +27 -0
  31. package/dist/lib/Query.d.ts +109 -0
  32. package/dist/lib/Query.js +74 -0
  33. package/dist/lib/Schema.d.ts +18 -0
  34. package/dist/lib/Schema.js +67 -0
  35. package/dist/lib/Selection.d.ts +20 -0
  36. package/dist/lib/Selection.js +7 -0
  37. package/dist/lib/Table.d.ts +62 -0
  38. package/dist/lib/Table.js +130 -0
  39. package/dist/lib/Target.d.ts +38 -0
  40. package/dist/lib/Target.js +42 -0
  41. package/dist/lib/Update.d.ts +4 -0
  42. package/dist/lib/Update.js +0 -0
  43. package/package.json +74 -74
@@ -0,0 +1,130 @@
1
+ // src/lib/Table.ts
2
+ import { Cursor } from "./Cursor.js";
3
+ import { Expr, ExprData } from "./Expr.js";
4
+ import { Query } from "./Query.js";
5
+ import { Selection } from "./Selection.js";
6
+ import { Target } from "./Target.js";
7
+ var Table = class extends Cursor.SelectMultiple {
8
+ [Selection.__tableType]() {
9
+ throw "assert";
10
+ }
11
+ constructor(schema) {
12
+ super(
13
+ Query.Select({
14
+ from: Target.Table(schema),
15
+ selection: ExprData.Row(Target.Table(schema))
16
+ })
17
+ );
18
+ Object.defineProperty(this, "schema", {
19
+ enumerable: false,
20
+ value: () => schema
21
+ });
22
+ if (schema.columns)
23
+ for (const column of Object.keys(schema.columns)) {
24
+ Object.defineProperty(this, column, {
25
+ enumerable: true,
26
+ get: () => this.get(column)
27
+ });
28
+ }
29
+ return new Proxy(this, {
30
+ get(target, key) {
31
+ return key in target ? target[key] : target.get(key);
32
+ }
33
+ });
34
+ }
35
+ fetch(id) {
36
+ return this.where(this.get("id").is(id)).first();
37
+ }
38
+ insertOne(record) {
39
+ return new Cursor(
40
+ Query.Insert({
41
+ into: this.schema(),
42
+ data: [record],
43
+ selection: ExprData.Row(Target.Table(this.schema())),
44
+ singleResult: true
45
+ })
46
+ );
47
+ }
48
+ insertAll(data) {
49
+ return new Cursor.Insert(this.schema()).values(...data);
50
+ }
51
+ set(data) {
52
+ return new Cursor.Update(
53
+ Query.Update({
54
+ table: this.schema()
55
+ })
56
+ ).set(data);
57
+ }
58
+ delete() {
59
+ return new Cursor.Delete(Query.Delete({ table: this.schema() }));
60
+ }
61
+ createTable() {
62
+ return new Cursor.CreateTable(this.schema());
63
+ }
64
+ as(alias) {
65
+ return new Table({ ...this.schema(), alias });
66
+ }
67
+ alias() {
68
+ return new Proxy(
69
+ {},
70
+ {
71
+ get: (_, key) => {
72
+ return this.as(key);
73
+ }
74
+ }
75
+ );
76
+ }
77
+ get(name) {
78
+ return new Expr(ExprData.Field(this.toExpr().expr, name));
79
+ }
80
+ toExpr() {
81
+ return new Expr(
82
+ ExprData.Row(Target.Table(this.schema()))
83
+ );
84
+ }
85
+ schema() {
86
+ throw new Error("Not implemented");
87
+ }
88
+ };
89
+ function table(options) {
90
+ const schema = {
91
+ ...options,
92
+ columns: Object.fromEntries(
93
+ Object.entries(options.columns).map(([key, column]) => {
94
+ const { data } = column;
95
+ return [key, { ...data, name: data.name || key }];
96
+ })
97
+ ),
98
+ indexes: {}
99
+ };
100
+ const indexes = Object.fromEntries(
101
+ Object.entries(
102
+ options.indexes ? options.indexes.call(
103
+ new Expr(ExprData.Row(Target.Table(schema)))
104
+ ) : {}
105
+ ).map(([key, index]) => {
106
+ const indexName = `${schema.name}.${key}`;
107
+ return [indexName, { name: indexName, ...index.data }];
108
+ })
109
+ );
110
+ return new Table({
111
+ ...schema,
112
+ indexes
113
+ });
114
+ }
115
+ ((table2) => {
116
+ function extend(target, extensions) {
117
+ return new Proxy(target, {
118
+ get(target2, key) {
119
+ if (key === "as")
120
+ return (...args) => extend(target2.as(...args), extensions);
121
+ return key in extensions ? extensions[key].bind(target2) : target2[key];
122
+ }
123
+ });
124
+ }
125
+ table2.extend = extend;
126
+ })(table || (table = {}));
127
+ export {
128
+ Table,
129
+ table
130
+ };
@@ -0,0 +1,38 @@
1
+ import { ExprData } from './Expr';
2
+ import { Query as QueryData } from './Query';
3
+ import { Schema } from './Schema';
4
+ export declare enum TargetType {
5
+ Expr = "Expr",
6
+ Query = "Query",
7
+ Table = "Table",
8
+ Join = "Join"
9
+ }
10
+ export type Target = Target.Expr | Target.Query | Target.Table | Target.Join;
11
+ export declare namespace Target {
12
+ interface Expr {
13
+ type: TargetType.Expr;
14
+ expr: ExprData;
15
+ alias?: string;
16
+ }
17
+ function Expr(expr: ExprData, alias?: string): Expr;
18
+ interface Query {
19
+ type: TargetType.Query;
20
+ query: QueryData;
21
+ alias?: string;
22
+ }
23
+ function Query(query: QueryData, alias?: string): Query;
24
+ interface Table {
25
+ type: TargetType.Table;
26
+ table: Schema;
27
+ }
28
+ function Table(table: Schema): Table;
29
+ interface Join {
30
+ type: TargetType.Join;
31
+ left: Target;
32
+ right: Target;
33
+ joinType: 'left' | 'inner';
34
+ on: ExprData;
35
+ }
36
+ function Join(left: Target, right: Target, joinType: 'left' | 'inner', on: ExprData): Join;
37
+ function source(from: Target): Schema | undefined;
38
+ }
@@ -0,0 +1,42 @@
1
+ // src/lib/Target.ts
2
+ var TargetType = /* @__PURE__ */ ((TargetType2) => {
3
+ TargetType2["Expr"] = "Expr";
4
+ TargetType2["Query"] = "Query";
5
+ TargetType2["Table"] = "Table";
6
+ TargetType2["Join"] = "Join";
7
+ return TargetType2;
8
+ })(TargetType || {});
9
+ var Target;
10
+ ((Target2) => {
11
+ function Expr(expr, alias) {
12
+ return { type: "Expr" /* Expr */, expr, alias };
13
+ }
14
+ Target2.Expr = Expr;
15
+ function Query(query, alias) {
16
+ return { type: "Query" /* Query */, query, alias };
17
+ }
18
+ Target2.Query = Query;
19
+ function Table(table) {
20
+ return { type: "Table" /* Table */, table };
21
+ }
22
+ Target2.Table = Table;
23
+ function Join(left, right, joinType, on) {
24
+ return { type: "Join" /* Join */, left, right, joinType, on };
25
+ }
26
+ Target2.Join = Join;
27
+ function source(from) {
28
+ switch (from.type) {
29
+ case "Table" /* Table */:
30
+ return from.table;
31
+ case "Join" /* Join */:
32
+ return source(from.left);
33
+ default:
34
+ return void 0;
35
+ }
36
+ }
37
+ Target2.source = source;
38
+ })(Target || (Target = {}));
39
+ export {
40
+ Target,
41
+ TargetType
42
+ };
@@ -0,0 +1,4 @@
1
+ import type { EV } from './Expr';
2
+ export type Update<Row> = Partial<{
3
+ [K in keyof Row]: EV<Row[K]>;
4
+ }>;
File without changes
package/package.json CHANGED
@@ -1,74 +1,74 @@
1
- {
2
- "name": "rado",
3
- "version": "0.3.0",
4
- "license": "MIT",
5
- "type": "module",
6
- "main": "./dist/index.js",
7
- "types": "./dist/index.d.ts",
8
- "exports": {
9
- ".": "./dist/index.js",
10
- "./*": "./dist/*.js",
11
- "./driver/bun:sqlite": "./dist/driver/bun-sqlite.js"
12
- },
13
- "typesVersions": {
14
- "*": {
15
- "driver/*": [
16
- "dist/driver/*.d.ts"
17
- ],
18
- "lib/*": [
19
- "dist/lib/*.d.ts"
20
- ],
21
- "driver/bun:sqlite": [
22
- "dist/driver/bun-sqlite.d.ts"
23
- ],
24
- "define/*": [
25
- "dist/define/*.d.ts"
26
- ],
27
- "sqlite/*": [
28
- "dist/sqlite/*.d.ts"
29
- ],
30
- "sqlite": [
31
- "dist/sqlite.d.ts"
32
- ],
33
- "util/*": [
34
- "dist/util/*.d.ts"
35
- ]
36
- }
37
- },
38
- "files": [
39
- "dist"
40
- ],
41
- "sideEffects": false,
42
- "scripts": {
43
- "build": "tsc -p tsconfig.build.json && tsx build.ts",
44
- "test": "tsx test",
45
- "test:bun": "bun test/index.ts --driver=bun:sqlite",
46
- "profile": "cross-env PROFILE=true tsx build.ts && cd bin && (rimraf CPU*.cpuprofile || true) && node --cpu-prof --cpu-prof-interval=100 test && speedscope CPU*.cpuprofile",
47
- "prepublishOnly": "tsc -p tsconfig.build.json && tsx build.ts"
48
- },
49
- "devDependencies": {
50
- "@types/better-sqlite3": "^5.4.1",
51
- "@types/glob": "^8.0.0",
52
- "@types/sql.js": "^1.4.2",
53
- "better-sqlite3": "^7.5.1",
54
- "bun-types": "^0.5.0",
55
- "cross-env": "^7.0.3",
56
- "esbuild": "^0.17.10",
57
- "glob": "^8.0.3",
58
- "rimraf": "^4.1.2",
59
- "sade": "^1.8.1",
60
- "speedscope": "^1.15.0",
61
- "sql.js": "^1.8.0",
62
- "sqlite3": "^5.1.6",
63
- "tsx": "^3.12.3",
64
- "typescript": "beta",
65
- "uvu": "^0.5.6"
66
- },
67
- "volta": {
68
- "node": "18.12.1"
69
- },
70
- "packageManager": "yarn@3.3.1",
71
- "resolutions": {
72
- "esbuild": "0.17.10"
73
- }
74
- }
1
+ {
2
+ "name": "rado",
3
+ "version": "0.3.2",
4
+ "license": "MIT",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": "./dist/index.js",
10
+ "./*": "./dist/*.js",
11
+ "./driver/bun:sqlite": "./dist/driver/bun-sqlite.js"
12
+ },
13
+ "typesVersions": {
14
+ "*": {
15
+ "driver/*": [
16
+ "dist/driver/*.d.ts"
17
+ ],
18
+ "lib/*": [
19
+ "dist/lib/*.d.ts"
20
+ ],
21
+ "driver/bun:sqlite": [
22
+ "dist/driver/bun-sqlite.d.ts"
23
+ ],
24
+ "define/*": [
25
+ "dist/define/*.d.ts"
26
+ ],
27
+ "sqlite/*": [
28
+ "dist/sqlite/*.d.ts"
29
+ ],
30
+ "sqlite": [
31
+ "dist/sqlite.d.ts"
32
+ ],
33
+ "util/*": [
34
+ "dist/util/*.d.ts"
35
+ ]
36
+ }
37
+ },
38
+ "files": [
39
+ "dist"
40
+ ],
41
+ "sideEffects": false,
42
+ "scripts": {
43
+ "build": "tsc -p tsconfig.build.json && tsx build.ts",
44
+ "test": "tsx test",
45
+ "test:bun": "bun test/index.ts --driver=bun:sqlite",
46
+ "profile": "cross-env PROFILE=true tsx build.ts && cd bin && (rimraf CPU*.cpuprofile || true) && node --cpu-prof --cpu-prof-interval=100 test && speedscope CPU*.cpuprofile",
47
+ "prepublishOnly": "tsc -p tsconfig.build.json && tsx build.ts"
48
+ },
49
+ "devDependencies": {
50
+ "@types/better-sqlite3": "^5.4.1",
51
+ "@types/glob": "^8.0.0",
52
+ "@types/sql.js": "^1.4.2",
53
+ "better-sqlite3": "^7.5.1",
54
+ "bun-types": "^0.5.0",
55
+ "cross-env": "^7.0.3",
56
+ "esbuild": "^0.17.10",
57
+ "glob": "^8.0.3",
58
+ "rimraf": "^4.1.2",
59
+ "sade": "^1.8.1",
60
+ "speedscope": "^1.15.0",
61
+ "sql.js": "^1.8.0",
62
+ "sqlite3": "^5.1.6",
63
+ "tsx": "^3.12.3",
64
+ "typescript": "beta",
65
+ "uvu": "^0.5.6"
66
+ },
67
+ "volta": {
68
+ "node": "18.12.1"
69
+ },
70
+ "packageManager": "yarn@3.3.1",
71
+ "resolutions": {
72
+ "esbuild": "0.17.10"
73
+ }
74
+ }