@tinyshed/tinystore 0.1.0-rc.4 → 0.1.0-rc.6

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/README.md +37 -37
  2. package/bin/tinystore.js +12 -1
  3. package/dist/backup.d.ts +33 -0
  4. package/dist/backup.js +49 -0
  5. package/dist/blobs.d.ts +160 -79
  6. package/dist/blobs.js +510 -217
  7. package/dist/channels.d.ts +90 -0
  8. package/dist/channels.js +291 -0
  9. package/dist/clock.js +3 -3
  10. package/dist/config.d.ts +209 -86
  11. package/dist/config.js +581 -538
  12. package/dist/connection.d.ts +64 -2
  13. package/dist/connection.js +201 -16
  14. package/dist/console.d.ts +27 -3
  15. package/dist/console.js +165 -12
  16. package/dist/dotenv.d.ts +7 -0
  17. package/dist/dotenv.js +79 -0
  18. package/dist/errors.d.ts +61 -1
  19. package/dist/errors.js +81 -1
  20. package/dist/handles.d.ts +44 -2
  21. package/dist/handles.js +81 -2
  22. package/dist/index.d.ts +17 -11
  23. package/dist/index.js +5 -3
  24. package/dist/instruments.d.ts +177 -0
  25. package/dist/instruments.js +819 -0
  26. package/dist/jobs.d.ts +335 -239
  27. package/dist/jobs.js +716 -536
  28. package/dist/json.d.ts +2 -0
  29. package/dist/json.js +122 -0
  30. package/dist/kv.d.ts +130 -243
  31. package/dist/kv.js +273 -640
  32. package/dist/limits.d.ts +80 -0
  33. package/dist/limits.js +139 -0
  34. package/dist/locks.d.ts +62 -0
  35. package/dist/locks.js +237 -0
  36. package/dist/logger.d.ts +45 -9
  37. package/dist/logger.js +150 -38
  38. package/dist/metrics.d.ts +210 -209
  39. package/dist/metrics.js +319 -556
  40. package/dist/once.d.ts +19 -18
  41. package/dist/once.js +74 -63
  42. package/dist/query.d.ts +181 -0
  43. package/dist/query.js +788 -0
  44. package/dist/records.d.ts +241 -150
  45. package/dist/records.js +507 -291
  46. package/dist/runtime/addon.d.ts +14 -0
  47. package/dist/runtime/addon.js +69 -0
  48. package/dist/runtime/bun.js +5 -7
  49. package/dist/runtime/node.js +5 -7
  50. package/dist/runtime/pipe.d.ts +17 -0
  51. package/dist/runtime/pipe.js +133 -0
  52. package/dist/runtime/shared.d.ts +6 -0
  53. package/dist/runtime/shared.js +19 -0
  54. package/dist/runtime.d.ts +5 -2
  55. package/dist/search.d.ts +189 -0
  56. package/dist/search.js +281 -0
  57. package/dist/session.d.ts +31 -3
  58. package/dist/session.js +153 -41
  59. package/dist/sql.d.ts +228 -78
  60. package/dist/sql.js +745 -240
  61. package/dist/store.d.ts +244 -24
  62. package/dist/store.js +270 -67
  63. package/dist/time.d.ts +5 -1
  64. package/dist/time.js +22 -2
  65. package/dist/tx.d.ts +61 -0
  66. package/dist/tx.js +314 -0
  67. package/dist/wire/codec.d.ts +23 -7
  68. package/dist/wire/codec.js +56 -35
  69. package/dist/wire/frame.d.ts +2 -0
  70. package/dist/wire/frame.js +31 -14
  71. package/dist/wire/messages.d.ts +259 -0
  72. package/dist/wire/messages.js +22 -0
  73. package/dist/wire/msgpack.d.ts +49 -1
  74. package/dist/wire/msgpack.js +293 -56
  75. package/dist/wire/protocol.d.ts +2683 -0
  76. package/dist/wire/protocol.js +10846 -0
  77. package/package.json +39 -38
  78. package/src/backup.ts +81 -0
  79. package/src/blobs.ts +678 -301
  80. package/src/channels.ts +377 -0
  81. package/src/clock.ts +4 -4
  82. package/src/config.ts +902 -612
  83. package/src/connection.ts +279 -21
  84. package/src/console.ts +180 -12
  85. package/src/dotenv.ts +82 -0
  86. package/src/errors.ts +105 -0
  87. package/src/handles.ts +157 -8
  88. package/src/index.ts +158 -52
  89. package/src/instruments.ts +1042 -0
  90. package/src/jobs.ts +1017 -733
  91. package/src/json.ts +133 -0
  92. package/src/kv.ts +424 -847
  93. package/src/limits.ts +202 -0
  94. package/src/locks.ts +320 -0
  95. package/src/logger.ts +209 -40
  96. package/src/metrics.ts +557 -752
  97. package/src/once.ts +86 -83
  98. package/src/query.ts +1005 -0
  99. package/src/records.ts +795 -418
  100. package/src/runtime/addon.ts +99 -0
  101. package/src/runtime/bun.ts +5 -7
  102. package/src/runtime/node.ts +5 -7
  103. package/src/runtime/pipe.ts +178 -0
  104. package/src/runtime/shared.ts +20 -0
  105. package/src/runtime.ts +5 -2
  106. package/src/search.ts +480 -0
  107. package/src/session.ts +187 -41
  108. package/src/sql.ts +993 -306
  109. package/src/store.ts +473 -78
  110. package/src/time.ts +48 -3
  111. package/src/tx.ts +426 -0
  112. package/src/wire/codec.ts +78 -37
  113. package/src/wire/frame.ts +44 -14
  114. package/src/wire/messages.ts +25 -0
  115. package/src/wire/msgpack.ts +327 -56
  116. package/src/wire/protocol.ts +11709 -0
  117. package/dist/limiter.d.ts +0 -45
  118. package/dist/limiter.js +0 -68
  119. package/dist/quota.d.ts +0 -44
  120. package/dist/quota.js +0 -98
  121. package/src/limiter.ts +0 -99
  122. package/src/quota.ts +0 -137
package/dist/once.d.ts CHANGED
@@ -1,31 +1,32 @@
1
1
  import type { Link } from './connection.ts';
2
- import type { Values } from './kv.ts';
3
- import type { Duration } from './time.ts';
2
+ import { type Duration } from './time.ts';
4
3
  import type { Key } from './wire/codec.ts';
5
4
  export interface OnceOptions {
6
5
  /** how long an answer is kept: a day when absent */
7
- defaultTtl?: Duration;
6
+ keep?: Duration | undefined;
8
7
  }
9
- /** Answers kept once a key: open them with `store.kv.once(name)`. */
10
- export declare class Once<V> {
8
+ /** Answers kept once a key: open them with `store.once(name)`. */
9
+ export declare class Once<T> {
11
10
  #private;
12
11
  readonly name: string;
13
- /** Answers come from `store.kv.once` and their `of`. */
14
- constructor(link: Link, name: string, open: Uint8Array, values: Values<V>, owners: (string | Uint8Array)[]);
12
+ /** Answers come from `store.once` and their `under`. */
13
+ constructor(link: Link, name: string, open: Uint8Array, under: readonly string[]);
15
14
  /** The answers of a branch, each key apart from the same key elsewhere. */
16
- of(...owners: Key[]): Once<V>;
15
+ under(...owners: Key[]): Once<T>;
17
16
  /**
18
- * The answer kept under key, or fn's, which is kept. A call of a key
19
- * another call is running waits for it and gets its answer; a throw of fn
20
- * keeps nothing and is thrown, so the next call runs fn again. A
21
- * connection lost after fn returned and before its answer was kept is
22
- * OutcomeUnknownError.
17
+ * The answer kept for key, or fn's, which is kept. A run of a key that
18
+ * another runs, here or in another process, waits for it and gets its
19
+ * answer; a throw of fn keeps nothing and is thrown, so the next run runs
20
+ * fn again. A connection lost after fn returned and before its answer was
21
+ * kept is OutcomeUnknownError.
23
22
  *
24
23
  * const receipt = await charges.run(requestId, () => pay.charge(order, requestId))
25
24
  */
26
- run(key: Key, fn: () => V | Promise<V>): Promise<V>;
27
- /** The answer kept under key, undefined when none is. */
28
- get(key: Key): Promise<V | undefined>;
29
- /** Forgets the answer kept under key, so that the next run runs again. */
30
- delete(key: Key): Promise<void>;
25
+ run(key: Key, fn: () => T | Promise<T>): Promise<T>;
26
+ /** The answer kept for key, undefined when none is. */
27
+ get(key: Key): Promise<T | undefined>;
28
+ /** Forgets the answer kept for key, so that its next run runs fn again. */
29
+ delete(key: Key): Promise<boolean>;
31
30
  }
31
+ /** What a once's open sends, checked before anything leaves. */
32
+ export declare function onceOpen(name: string, options?: OnceOptions): Uint8Array;
package/dist/once.js CHANGED
@@ -1,84 +1,88 @@
1
- // Answers a function gives once a key, as Go's kv.Once keeps them: a request
2
- // sent again is answered as the first was rather than done twice. The server
3
- // lets one call of a key run its function at a time, every client of the
4
- // store included, and keeps what it returned.
1
+ // A function run once a key, its answer kept: a request sent twice is answered
2
+ // as the first was rather than done twice. The core lets one run of a key go
3
+ // at a time, every client of the store included: it answers the kept answer,
4
+ // or hands the run to this client and keeps what it sends back.
5
5
  import { currentSignal } from './cancel.js';
6
- import { OutcomeUnknownError } from './errors.js';
7
- import { handleOn, ownerText } from './handles.js';
8
- import { LostError, watch } from './session.js';
9
- import { KvCall, KvEntry, methods } from './wire/messages.js';
10
- /** Answers kept once a key: open them with `store.kv.once(name)`. */
6
+ import { OutcomeUnknownError, ProtocolError } from './errors.js';
7
+ import { checkName, handleOn } from './handles.js';
8
+ import { callOn, jsonValues, keyText, underField } from './kv.js';
9
+ import { ConnectionLostError, watch } from './session.js';
10
+ import { ms } from './time.js';
11
+ import { KvAnswer, KvCall, KvFound, KvOnceOpen, methods } from './wire/protocol.js';
12
+ /** Answers kept once a key: open them with `store.once(name)`. */
11
13
  export class Once {
12
14
  name;
13
15
  #link;
14
16
  #open;
15
17
  #values;
16
- #owners;
17
- /** Answers come from `store.kv.once` and their `of`. */
18
- constructor(link, name, open, values, owners) {
18
+ #under;
19
+ /** Answers come from `store.once` and their `under`. */
20
+ constructor(link, name, open, under) {
19
21
  this.#link = link;
20
22
  this.name = name;
21
23
  this.#open = open;
22
- this.#values = values;
23
- this.#owners = owners;
24
+ this.#values = jsonValues;
25
+ this.#under = under;
24
26
  }
25
27
  /** The answers of a branch, each key apart from the same key elsewhere. */
26
- of(...owners) {
27
- return new Once(this.#link, this.name, this.#open, this.#values, [
28
- ...this.#owners,
29
- ...owners.map(ownerText),
30
- ]);
28
+ under(...owners) {
29
+ return new Once(this.#link, this.name, this.#open, [...this.#under, ...owners.map(keyText)]);
31
30
  }
32
31
  /**
33
- * The answer kept under key, or fn's, which is kept. A call of a key
34
- * another call is running waits for it and gets its answer; a throw of fn
35
- * keeps nothing and is thrown, so the next call runs fn again. A
36
- * connection lost after fn returned and before its answer was kept is
37
- * OutcomeUnknownError.
32
+ * The answer kept for key, or fn's, which is kept. A run of a key that
33
+ * another runs, here or in another process, waits for it and gets its
34
+ * answer; a throw of fn keeps nothing and is thrown, so the next run runs
35
+ * fn again. A connection lost after fn returned and before its answer was
36
+ * kept is OutcomeUnknownError.
38
37
  *
39
38
  * const receipt = await charges.run(requestId, () => pay.charge(order, requestId))
40
39
  */
41
40
  async run(key, fn) {
42
- const { stream, kept } = await this.#claim(key);
43
- if (stream === undefined) {
44
- return await this.#values.decode(kept ?? null);
41
+ const handed = await this.#claim(key);
42
+ if (!(handed instanceof Run)) {
43
+ return handed.value;
45
44
  }
46
45
  let answer;
47
- let body;
46
+ let kept;
48
47
  try {
49
48
  answer = await fn();
50
- body = KvEntry.encode({ found: true, value: await this.#values.encode(answer) });
49
+ kept = KvAnswer.encode({ found: true, value: this.#values.encode(answer) });
51
50
  }
52
51
  catch (err) {
53
- await end(stream, KvEntry.encode({})).catch(() => { });
52
+ await handed.end(KvAnswer.encode({})).catch(() => { });
54
53
  throw err;
55
54
  }
56
- await end(stream, body);
55
+ await handed.end(kept);
57
56
  return answer;
58
57
  }
59
- /** The answer kept under key, undefined when none is. */
58
+ /** The answer kept for key, undefined when none is. */
60
59
  async get(key) {
61
- const e = await this.#call('kv.get', key, 'read');
62
- return e.found === true ? await this.#values.decode(e.value ?? null) : undefined;
60
+ const body = await this.#call('kv.once.get', key, 'read');
61
+ const kept = KvAnswer.decode(body);
62
+ return kept.found === true ? this.#values.decode(kept.value ?? null) : undefined;
63
63
  }
64
- /** Forgets the answer kept under key, so that the next run runs again. */
64
+ /** Forgets the answer kept for key, so that its next run runs fn again. */
65
65
  async delete(key) {
66
- await this.#call('kv.delete', key, 'write');
66
+ return KvFound.decode(await this.#call('kv.once.delete', key, 'write')).found === true;
67
67
  }
68
- // asks for key's run: the answer kept under it, or the stream the server
69
- // handed the run on, which a lost connection asks for again
68
+ // asks for key's run: the answer kept for it, or the run the core handed
69
+ // over, which a connection lost before the answer asks for again
70
70
  async #claim(key) {
71
71
  return this.#link.run('read', async (connection) => {
72
- const handle = await handleOn(connection, methods['kv.open'], this.#open);
73
- const ask = KvCall.encode({ handle, owners: this.#ownersField(), key });
74
- const stream = await connection.session.open(methods['kv.run'], ask, false);
72
+ const handle = await handleOn(connection, methods['kv.once.open'], this.#open);
73
+ const call = KvCall.encode({ handle, under: underField(this.#under), key });
74
+ const stream = await connection.session.open(methods['kv.once.run'], call, false);
75
75
  const unwatch = watch(currentSignal(), stream);
76
76
  try {
77
77
  const first = await stream.next();
78
- if (first.end) {
79
- return { kept: KvEntry.decode(first.body).value };
78
+ const offered = KvAnswer.decode(first.body);
79
+ if (!first.end) {
80
+ return new Run(stream);
80
81
  }
81
- return { stream };
82
+ if (offered.found !== true) {
83
+ throw new ProtocolError(`kv once ${this.name}: a run ended without its answer`);
84
+ }
85
+ return { value: this.#values.decode(offered.value ?? null) };
82
86
  }
83
87
  catch (err) {
84
88
  stream.cancel();
@@ -89,28 +93,35 @@ export class Once {
89
93
  }
90
94
  });
91
95
  }
92
- async #call(method, key, idempotence) {
93
- return this.#link.run(idempotence, async (connection) => {
94
- const handle = await handleOn(connection, methods['kv.open'], this.#open);
95
- const body = KvCall.encode({ handle, owners: this.#ownersField(), key });
96
- return KvEntry.decode(await connection.session.call(methods[method], body));
97
- });
98
- }
99
- #ownersField() {
100
- return this.#owners.length > 0 ? this.#owners : undefined;
96
+ #call(method, key, idempotence) {
97
+ return callOn(this.#link, 'kv.once.open', this.#open, this.#under, method, { key }, idempotence);
101
98
  }
102
99
  }
103
- // sends what a run keeps as the stream's last DATA, and waits for the
104
- // server's, which comes once it is kept
105
- async function end(stream, body) {
106
- try {
107
- await stream.send(body, true);
108
- await stream.next();
100
+ /** A run the core handed to this client, until it sends what to keep. */
101
+ class Run {
102
+ #stream;
103
+ constructor(stream) {
104
+ this.#stream = stream;
109
105
  }
110
- catch (err) {
111
- if (err instanceof LostError) {
112
- throw new OutcomeUnknownError(`the connection was lost before the answer was kept; the next run may run again: ${err.message}`);
106
+ /** Sends the run's answer as the stream's last DATA, and waits for the core's, once it is kept. */
107
+ async end(answer) {
108
+ try {
109
+ await this.#stream.send(answer, true);
110
+ await this.#stream.next();
111
+ }
112
+ catch (err) {
113
+ if (err instanceof ConnectionLostError) {
114
+ throw new OutcomeUnknownError(`the connection was lost before the answer was kept; the next run may run again: ${err.message}`);
115
+ }
116
+ throw err;
113
117
  }
114
- throw err;
115
118
  }
116
119
  }
120
+ /** What a once's open sends, checked before anything leaves. */
121
+ export function onceOpen(name, options = {}) {
122
+ checkName(name, 'once');
123
+ return KvOnceOpen.encode({
124
+ name,
125
+ keep: options.keep === undefined ? undefined : ms(options.keep),
126
+ });
127
+ }
@@ -0,0 +1,181 @@
1
+ import { type StandardSchemaV1 } from './schema.ts';
2
+ import { type Condition, type Done, type Embeddable, type Row, type Runner, Sql, type SqlArg, type SqlValue } from './sql.ts';
3
+ /** How a column SQLite keeps otherwise reads in JavaScript. */
4
+ export type ColumnType = 'bool' | 'time' | 'json' | 'bigint';
5
+ export interface TableOptions {
6
+ /** the columns SQLite keeps as 0 or 1, unix milliseconds, JSON text or an integer past 2^53 */
7
+ types?: Record<string, ColumnType>;
8
+ /** a Standard Schema, zod's or valibot's, that checks each row read */
9
+ schema?: StandardSchemaV1;
10
+ }
11
+ /** What an upsert does when the row's key is taken. */
12
+ export interface UpsertOptions<T> {
13
+ /** the columns whose value, taken, makes the insert an update: the key */
14
+ conflict: string | readonly string[];
15
+ /** the columns the update sets from the row; none other changes */
16
+ update: readonly (keyof T & string)[];
17
+ /** the condition the row that holds the key must meet, its owner's, or it stays as it is */
18
+ where?: Condition | undefined;
19
+ }
20
+ /** A page of a query's rows, and the cursor that reads the next; none after the last. */
21
+ export interface RowPage<T> {
22
+ rows: T[];
23
+ next?: string;
24
+ }
25
+ type Direction = 'asc' | 'desc';
26
+ /** A condition of a query, and whether it may stand in an and without parentheses. */
27
+ interface Kept {
28
+ piece: Sql;
29
+ bare: boolean;
30
+ }
31
+ interface Parts {
32
+ table: string;
33
+ alias?: string | undefined;
34
+ select?: Sql | undefined;
35
+ joins: Sql[];
36
+ conditions: Kept[];
37
+ groups: string[];
38
+ having: Kept[];
39
+ order: {
40
+ piece: Sql;
41
+ column?: string | undefined;
42
+ direction: Direction;
43
+ }[];
44
+ limit?: number | undefined;
45
+ offset?: number | undefined;
46
+ includes: Included[];
47
+ }
48
+ /** A query whose rows each row of another holds as a list under a name. */
49
+ interface Included {
50
+ name: string;
51
+ parts: Parts;
52
+ /** how the included rows read: their table's types and schema */
53
+ source: Source;
54
+ /** the names of the columns its select gives, in their order */
55
+ columns: string[];
56
+ }
57
+ /** How a table reads and writes: its runner, its name, and how its rows read. */
58
+ interface Source {
59
+ runner: Runner;
60
+ types: Record<string, ColumnType>;
61
+ schema?: StandardSchemaV1 | undefined;
62
+ }
63
+ /**
64
+ * A query on a table: a value, each call returning a new one, so that the
65
+ * first stays as it was. `all`, `one`, `scalar`, `count`, `each` and `list`
66
+ * read; `update` and `delete` write.
67
+ *
68
+ * const urgent = await orders
69
+ * .where({ status: 'pending', deleted: false })
70
+ * .where(sql.or(sql`amount >= ${1000}`, { priority: 'high' }))
71
+ * .orderBy('created_at', 'desc')
72
+ * .limit(50)
73
+ * .all()
74
+ */
75
+ export declare class Query<T = Row> implements Embeddable {
76
+ #private;
77
+ /** Queries come from `db.table`. */
78
+ constructor(source: Source, parts: Parts);
79
+ /**
80
+ * Adds a condition with and: equal values, `null` as is null and a list
81
+ * as in (…); a piece of SQL from `sql`; or text and the values of its ?s.
82
+ * `undefined` is InvalidError, never a filter left out.
83
+ */
84
+ where(condition: Condition | string, ...values: unknown[]): Query<T>;
85
+ /** The columns a row holds, as SQL text, and the shape of the row they make. */
86
+ select<R = Row>(columns: string | Sql): Query<R>;
87
+ /**
88
+ * Gives each row the rows of another query as a list under `name`, from
89
+ * the same statement: the query names the row it belongs to in its
90
+ * `where`, by this table's alias, names its columns with `select`, and has
91
+ * a `limit`, which counts for each row. Every value comes back as it is
92
+ * kept, bytes and integers past 2^53 among them.
93
+ *
94
+ * const latest = db.table<Post>('posts as p').select<{ id: string; title: string }>('p.id, p.title')
95
+ * .where('p.author_id = u.id').orderBy('p.id', 'desc').limit(3)
96
+ * const authors = await db.table<User>('users as u').include('posts', latest).all()
97
+ */
98
+ include<N extends string, C>(name: N, query: Query<C>): Query<T & Record<N, C[]>>;
99
+ /** Joins a table, `'users as u'`, on a condition as SQL text or a piece of SQL. */
100
+ join(table: string, on: string | Sql): Query<T>;
101
+ /** Joins a table whose columns may be null where no row of it meets the condition. */
102
+ leftJoin(table: string, on: string | Sql): Query<T>;
103
+ /** Groups the rows by columns, quoted as names. */
104
+ groupBy(...columns: string[]): Query<T>;
105
+ /** A condition on the groups, as `where` takes one. */
106
+ having(condition: Condition | string, ...values: unknown[]): Query<T>;
107
+ /**
108
+ * Orders the rows by a column, quoted as a name, so that a sort a request
109
+ * chooses cannot be SQL, or by a piece of SQL: `` orderBy(sql`lower(title)`) ``.
110
+ */
111
+ orderBy(column: string | Sql, direction?: Direction): Query<T>;
112
+ limit(rows: number): Query<T>;
113
+ offset(rows: number): Query<T>;
114
+ /** The text and the values the query sends, to read or to log. */
115
+ toSQL(): {
116
+ text: string;
117
+ values: SqlArg[];
118
+ };
119
+ /** The query inside another piece of SQL: a subquery, in parentheses. */
120
+ embedded(): Sql;
121
+ all(): Promise<T[]>;
122
+ one(): Promise<T | undefined>;
123
+ scalar<V = SqlValue>(): Promise<V>;
124
+ /** Every row the conditions match, without the order and the limit. */
125
+ count(): Promise<number>;
126
+ /** The rows one at a time, as their parts arrive. */
127
+ each(): AsyncGenerator<T>;
128
+ /**
129
+ * A page after the last row of the one before, by the query's order,
130
+ * which ends in a unique column so that no row is read twice or skipped.
131
+ * `next` reads the next page, and only of this query.
132
+ *
133
+ * const first = await orders.orderBy('created_at', 'desc').orderBy('id', 'desc').list({ limit: 50 })
134
+ * const second = await orders.orderBy('created_at', 'desc').orderBy('id', 'desc').list({ limit: 50, after: first.next })
135
+ */
136
+ list(options?: {
137
+ limit?: number | undefined;
138
+ after?: string | undefined;
139
+ }): Promise<RowPage<T>>;
140
+ /** SQLite's plan for the query, a line a step. */
141
+ explain(): Promise<string[]>;
142
+ /** Sets columns of the rows the conditions match, and says how many changed. */
143
+ update(values: {
144
+ [K in keyof T]?: T[K] | Sql;
145
+ } & Record<string, unknown>): Promise<Done>;
146
+ /** Deletes the rows the conditions match, and says how many it deleted. */
147
+ delete(): Promise<Done>;
148
+ /** A row as the table's types and schema read it. */
149
+ protected read(row: Row): Promise<T>;
150
+ protected get source(): Source;
151
+ protected get parts(): Parts;
152
+ }
153
+ /**
154
+ * A table: its queries, and its rows' inserts and upserts.
155
+ *
156
+ * const notes = db.table<Note>('notes', { types: { done: 'bool', tags: 'json', created_at: 'time' } })
157
+ * const note = await notes.insert({ id: uuidv7(), author_id: userId, title: 'Buy milk', done: false, tags: [], created_at: new Date() })
158
+ */
159
+ export declare class Table<T = Row> extends Query<T> {
160
+ readonly name: string;
161
+ /** Tables come from `db.table` and `tx.table`. */
162
+ constructor(runner: Runner, name: string, options?: TableOptions);
163
+ /** Inserts a row and gives it back as the file keeps it; a list of rows is one write, all of them or none. */
164
+ insert(row: Partial<T>): Promise<T>;
165
+ insert(rows: readonly Partial<T>[]): Promise<T[]>;
166
+ /**
167
+ * Inserts a row, or, when its key is taken, sets the columns `update`
168
+ * names on the row that holds it, if that row meets `where`. It gives
169
+ * back the row as the file keeps it, or undefined when `where` kept it.
170
+ */
171
+ upsert(row: Partial<T>, options: UpsertOptions<T>): Promise<T | undefined>;
172
+ }
173
+ /**
174
+ * The names of the columns a select's text gives, in their order: a column's
175
+ * own name, or what follows its `as`. An expression without a name is
176
+ * refused, since its rows could not be given their fields.
177
+ */
178
+ export declare function namesOf(select: string, describe: string): string[];
179
+ /** The rows an included query gave, read from their literals: `(1,'it''s',NULL),(2,X'00ff',1.5)`. */
180
+ export declare function literalRows(text: string): SqlValue[][];
181
+ export {};