kern-db 0.0.0-stage → 0.2.0

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.
@@ -0,0 +1,77 @@
1
+ /** PostgreSQL text representation of a value, as a driver sends a parameter and returns a value of a result; `null` is SQL `NULL`. */
2
+ type TextValue = string | null;
3
+ /** SQL statement ready for a driver. */
4
+ interface SqlStatement {
5
+ readonly text: string;
6
+ /** Text representations of the parameters; PostgreSQL infers their types from the statement text. */
7
+ readonly parameters: readonly TextValue[];
8
+ }
9
+ /** Creates a statement from SQL text and the text representations of its parameters, such as `createStatement("BEGIN")`. */
10
+ declare function createStatement(text: string, parameters?: readonly TextValue[]): SqlStatement;
11
+ /** Result of a statement. */
12
+ interface DriverResult {
13
+ /** Command of the tag that PostgreSQL completed the statement with, such as `SELECT` or `ROLLBACK` for a `COMMIT` of a failed transaction; a driver may give only the first word of a tag of several words, such as `CREATE` of `CREATE TABLE`; `null` for a statement that PostgreSQL completes without a tag, such as an empty text or only a comment. */
14
+ readonly command: string | null;
15
+ /** Number of rows that the command tag reports, such as the rows that an `UPDATE` changes, also without `RETURNING`; `0` when PostgreSQL reports none, such as for `BEGIN` or a statement without a command tag. */
16
+ readonly count: number;
17
+ /** Names of the result columns in their order, also when the statement returns no rows; none for a statement without result columns, such as `BEGIN` or an `UPDATE` without `RETURNING`. */
18
+ readonly columns: readonly string[];
19
+ /** Rows as PostgreSQL text representations of their values, in the order of the result columns. */
20
+ readonly rows: readonly (readonly TextValue[])[];
21
+ }
22
+ /**
23
+ * Physical database access: transport, pooling, and connections.
24
+ *
25
+ * A driver sends parameters as text without a declared type, so that the statement text alone determines their types, and returns values as text without parsing them.
26
+ * It rejects with `QueryError` a statement or script that PostgreSQL rejected, whose connection stays usable, and with `ConnectionError` any other failure of a statement, a script, or a connection.
27
+ */
28
+ interface Driver {
29
+ /**
30
+ * Executes a statement on any pooled connection.
31
+ *
32
+ * It rejects a statement that leaves its connection in a transaction, such as `BEGIN`, with `ConnectionError`, and leaves no transaction open on the pool.
33
+ */
34
+ execute(statement: SqlStatement): Promise<DriverResult>;
35
+ /**
36
+ * Executes a script of statements without parameters, such as DDL separated by semicolons, on any pooled connection, where PostgreSQL runs them in one implicit transaction.
37
+ *
38
+ * It rejects a script that leaves its connection in a transaction as `execute` rejects such a statement.
39
+ * A script whose statement PostgreSQL rejected in that transaction may reject with that `QueryError` instead.
40
+ * Either way, no transaction stays open on the pool.
41
+ */
42
+ executeScript(text: string): Promise<void>;
43
+ /** Reserves a dedicated connection, such as for a transaction or a session. */
44
+ acquire(): Promise<Connection>;
45
+ /**
46
+ * Closes the connections once the statements on the pool and the transactions and sessions on reserved connections end.
47
+ *
48
+ * From the call, it rejects a new statement or script on the pool and a new connection with `ConnectionError`.
49
+ */
50
+ close(): Promise<void>;
51
+ }
52
+ /**
53
+ * Checks whether `value` is a driver: an object with the methods of `Driver`, such as to reject a client of PostgreSQL passed instead of its driver.
54
+ *
55
+ * It checks the methods rather than a brand, since an application may write a driver of its own.
56
+ */
57
+ declare function isDriver(value: unknown): value is Driver;
58
+ /** Connection reserved by a driver, such as for a transaction or a session. */
59
+ interface Connection {
60
+ /**
61
+ * Executes a statement on the connection.
62
+ *
63
+ * Statements and scripts run one at a time in the order of calls, so a statement sent before `COMMIT` or `ROLLBACK` completes before it.
64
+ * A connection that is lost rejects every later statement and script with `ConnectionError`, in a transaction and outside one, rather than running it on a new connection.
65
+ */
66
+ execute(statement: SqlStatement): Promise<DriverResult>;
67
+ /** Executes a script of statements without parameters on the connection, in the order of calls with its statements. */
68
+ executeScript(text: string): Promise<void>;
69
+ /**
70
+ * Returns the connection to the pool once its statements complete, if PostgreSQL reported an idle transaction status after the last statement; otherwise the driver closes it, which rolls back a transaction left on it.
71
+ *
72
+ * The driver tells by itself how the statements on the connection ended.
73
+ * After a `ConnectionError`, a statement may still run or the connection may be lost, so the driver closes the connection, unless its client refused the statement without breaking the exchange of messages and still reads the status, such as postgres.js 4 for a statement of too many parameters.
74
+ */
75
+ release(): void | Promise<void>;
76
+ }
77
+ export { TextValue as a, SqlStatement as i, Driver as n, createStatement as o, DriverResult as r, isDriver as s, Connection as t };
@@ -0,0 +1,88 @@
1
+ // src/driver-error.ts
2
+ /** Marks an instance of `QueryError` of any copy of kern-db, which `instanceof QueryError` of another copy recognizes. */
3
+ const queryErrorBrand = /* @__PURE__ */ Symbol.for("kern-db.QueryError");
4
+ /** Marks an instance of `ConnectionError` of any copy of kern-db. */
5
+ const connectionErrorBrand = /* @__PURE__ */ Symbol.for("kern-db.ConnectionError");
6
+ /**
7
+ * Tells whether `value` is an instance of `errorClass`: by the brand of any copy of kern-db for `errorClass` itself, and by the prototype chain for its subclasses.
8
+ *
9
+ * An application can load several copies of kern-db, such as when it requires another version of kern-db than kern-orm does, and an error of one copy is then an instance of the class of another.
10
+ */
11
+ function isInstance(errorClass, root, brand, value) {
12
+ if (errorClass !== root) return Function.prototype[Symbol.hasInstance].call(errorClass, value);
13
+ return typeof value === "object" && value !== null && value[brand] === true;
14
+ }
15
+ /** Sets the brand of `error`, which is not enumerable, so that it does not show among the fields of the error. */
16
+ function setBrand(error, brand) {
17
+ Object.defineProperty(error, brand, { value: true });
18
+ }
19
+ /**
20
+ * Error of a statement that PostgreSQL rejected, such as for a violated constraint; the connection of the statement stays usable.
21
+ *
22
+ * A driver whose client gives the severity of an error only in the language of the server, such as node-postgres, tells such an error by its SQLSTATE when the server translates its messages.
23
+ * An error that ends the session with a code that a statement also gets, such as `40001` of a conflict with recovery on a replica, then rejects with `QueryError`, and the next statement on the connection with `ConnectionError`.
24
+ */
25
+ var QueryError = class QueryError extends Error {
26
+ name = "QueryError";
27
+ /** SQLSTATE of the error, such as `23505` for a violated unique constraint. */
28
+ code;
29
+ /** Name of the constraint that the statement violated, if any. */
30
+ constraint;
31
+ constructor(message, fields) {
32
+ super(message, "cause" in fields ? { cause: fields.cause } : void 0);
33
+ this.code = fields.code;
34
+ this.constraint = fields.constraint;
35
+ setBrand(this, queryErrorBrand);
36
+ }
37
+ /** Tells whether `value` is an instance of the class, including one of `QueryError` of another copy of kern-db. */
38
+ static [Symbol.hasInstance](value) {
39
+ return isInstance(this, QueryError, queryErrorBrand, value);
40
+ }
41
+ };
42
+ /**
43
+ * Error of a statement or connection that failed for another reason than PostgreSQL rejecting a statement, such as a lost connection, a timeout of the client, or a closed driver.
44
+ *
45
+ * The statement may have run or not, and its connection may be lost or in an unknown state of its transaction.
46
+ */
47
+ var ConnectionError = class ConnectionError extends Error {
48
+ name = "ConnectionError";
49
+ constructor(message, options) {
50
+ super(message, options);
51
+ setBrand(this, connectionErrorBrand);
52
+ }
53
+ /** Tells whether `value` is an instance of the class, including one of `ConnectionError` of another copy of kern-db. */
54
+ static [Symbol.hasInstance](value) {
55
+ return isInstance(this, ConnectionError, connectionErrorBrand, value);
56
+ }
57
+ };
58
+ /** SQLSTATE of five digits or uppercase letters; clients also give codes of their own, such as `ECONNRESET` or `CONNECTION_CLOSED`. */
59
+ const sqlState = /^[0-9A-Z]{5}$/;
60
+ /** SQLSTATE of an error that ends the session: of the classes of connection exceptions, authorization, operator intervention, and internal errors, and the timeouts of an idle transaction and of a transaction. */
61
+ const sessionEndingCode = /^(?:08|28|57P|XX|25P03$|25P04$)/;
62
+ /** Tells whether an error of the server of `severity` and SQLSTATE `code` ends its session. */
63
+ function isSessionEnding(severity, code) {
64
+ if (severity === "ERROR") return false;
65
+ if (severity === "FATAL" || severity === "PANIC") return true;
66
+ return sessionEndingCode.test(code);
67
+ }
68
+ /**
69
+ * Classifies an error of a client as `QueryError` or `ConnectionError`, by the fields of the PostgreSQL error it carries, for a driver to reject with.
70
+ *
71
+ * An error that kern-db has already classified returns as it is.
72
+ * An error without a severity or a SQLSTATE, such as of a client that lost its connection, is a `ConnectionError`, and so is one of severity `FATAL` or `PANIC`, which ends the session.
73
+ * An error of severity `ERROR` is a `QueryError`.
74
+ * With a translated severity, the SQLSTATE tells an error that ends the session, so a few errors of other codes that end it give `QueryError`.
75
+ */
76
+ function toDriverError(error, fields) {
77
+ if (error instanceof QueryError || error instanceof ConnectionError) return error;
78
+ const message = error instanceof Error ? error.message : String(error);
79
+ const { severity, code, constraint } = fields ?? {};
80
+ if (typeof severity !== "string" || typeof code !== "string" || !sqlState.test(code)) return new ConnectionError(message, { cause: error });
81
+ if (isSessionEnding(severity, code)) return new ConnectionError(message, { cause: error });
82
+ return new QueryError(message, {
83
+ code,
84
+ constraint: typeof constraint === "string" ? constraint : void 0,
85
+ cause: error
86
+ });
87
+ }
88
+ export { toDriverError as a, setBrand as i, QueryError as n, isInstance as r, ConnectionError as t };
@@ -0,0 +1,360 @@
1
+ import { a as TextValue, i as SqlStatement, n as Driver, o as createStatement, r as DriverResult, s as isDriver, t as Connection } from "./driver-CSfbXOBJ.mjs";
2
+ import { a as BaseDerivableType, c as Type, d as TypeOutput, f as TypeTransform, h as typeValues, i as AnyType, l as TypeInput, m as isType, n as AcceptedValues, o as DerivableType, p as defineType, r as AnyDerivableType, s as DerivableTypeWithParameters, t as AcceptedNull, u as TypeOptions } from "./type-CbrtxvDF.mjs";
3
+ import { A as OneRow, F as ResultRows, I as ValueRows, M as ResultByRows, N as ResultDecodeError, S as param, T as UntypedValue, _ as isDatabase, a as SqlQuery, b as SqlValue, d as DatabaseOptions, f as IsolationLevel, g as createDatabase, h as TransactionOptions, i as InitialSqlQueryState, j as OneValueRows, k as NotFoundError, m as SessionOptions, n as DecodedFields, o as SqlQueryResult, p as PollLockOptions, r as FieldTypes, s as SqlQueryState, t as AnySqlQuery, u as Database, w as sql, x as identifier, y as SqlFragment } from "./query-BrvYBvWC.mjs";
4
+ /**
5
+ * Error of a statement that PostgreSQL rejected, such as for a violated constraint; the connection of the statement stays usable.
6
+ *
7
+ * A driver whose client gives the severity of an error only in the language of the server, such as node-postgres, tells such an error by its SQLSTATE when the server translates its messages.
8
+ * An error that ends the session with a code that a statement also gets, such as `40001` of a conflict with recovery on a replica, then rejects with `QueryError`, and the next statement on the connection with `ConnectionError`.
9
+ */
10
+ export declare class QueryError extends Error {
11
+ readonly name = "QueryError";
12
+ /** SQLSTATE of the error, such as `23505` for a violated unique constraint. */
13
+ readonly code: string;
14
+ /** Name of the constraint that the statement violated, if any. */
15
+ readonly constraint: string | undefined;
16
+ constructor(message: string, fields: {
17
+ code: string;
18
+ constraint?: string | undefined;
19
+ cause?: unknown;
20
+ });
21
+ /** Tells whether `value` is an instance of the class, including one of `QueryError` of another copy of kern-db. */
22
+ static [Symbol.hasInstance]<T>(this: abstract new (...args: never) => T, value: unknown): value is T;
23
+ }
24
+ /**
25
+ * Error of a statement or connection that failed for another reason than PostgreSQL rejecting a statement, such as a lost connection, a timeout of the client, or a closed driver.
26
+ *
27
+ * The statement may have run or not, and its connection may be lost or in an unknown state of its transaction.
28
+ */
29
+ export declare class ConnectionError extends Error {
30
+ readonly name: string;
31
+ constructor(message: string, options?: {
32
+ cause?: unknown;
33
+ });
34
+ /** Tells whether `value` is an instance of the class, including one of `ConnectionError` of another copy of kern-db. */
35
+ static [Symbol.hasInstance]<T>(this: abstract new (...args: never) => T, value: unknown): value is T;
36
+ }
37
+ /** Fields of the PostgreSQL error that an error of a client carries, by which `toDriverError` classifies it. */
38
+ interface DriverErrorFields {
39
+ /**
40
+ * Severity of the error, such as `ERROR` or `FATAL`.
41
+ *
42
+ * Pass the severity in English when the client gives it, and the one in the language of the server otherwise.
43
+ */
44
+ readonly severity?: unknown;
45
+ /** SQLSTATE of the error, such as `23505`. */
46
+ readonly code?: unknown;
47
+ /** Name of the constraint that the statement violated. */
48
+ readonly constraint?: unknown;
49
+ }
50
+ /**
51
+ * Classifies an error of a client as `QueryError` or `ConnectionError`, by the fields of the PostgreSQL error it carries, for a driver to reject with.
52
+ *
53
+ * An error that kern-db has already classified returns as it is.
54
+ * An error without a severity or a SQLSTATE, such as of a client that lost its connection, is a `ConnectionError`, and so is one of severity `FATAL` or `PANIC`, which ends the session.
55
+ * An error of severity `ERROR` is a `QueryError`.
56
+ * With a translated severity, the SQLSTATE tells an error that ends the session, so a few errors of other codes that end it give `QueryError`.
57
+ */
58
+ export declare function toDriverError(error: unknown, fields?: DriverErrorFields): QueryError | ConnectionError;
59
+ /**
60
+ * Condition names of the SQLSTATE codes of PostgreSQL errors, by code: the codes of type `E` with a condition name, which PL/pgSQL takes in `EXCEPTION WHEN`, under the headings of their classes.
61
+ *
62
+ * A code that ends in `000` is the condition of its class.
63
+ * A few names have two codes, such as `null_value_not_allowed`.
64
+ */
65
+ declare const conditionsByCode: {
66
+ readonly "03000": "sql_statement_not_yet_complete";
67
+ readonly "08000": "connection_exception";
68
+ readonly "08003": "connection_does_not_exist";
69
+ readonly "08006": "connection_failure";
70
+ readonly "08001": "sqlclient_unable_to_establish_sqlconnection";
71
+ readonly "08004": "sqlserver_rejected_establishment_of_sqlconnection";
72
+ readonly "08007": "transaction_resolution_unknown";
73
+ readonly "08P01": "protocol_violation";
74
+ readonly "09000": "triggered_action_exception";
75
+ readonly "0A000": "feature_not_supported";
76
+ readonly "0B000": "invalid_transaction_initiation";
77
+ readonly "0F000": "locator_exception";
78
+ readonly "0F001": "invalid_locator_specification";
79
+ readonly "0L000": "invalid_grantor";
80
+ readonly "0LP01": "invalid_grant_operation";
81
+ readonly "0P000": "invalid_role_specification";
82
+ readonly "0Z000": "diagnostics_exception";
83
+ readonly "0Z002": "stacked_diagnostics_accessed_without_active_handler";
84
+ readonly "10608": "invalid_argument_for_xquery";
85
+ readonly "20000": "case_not_found";
86
+ readonly "21000": "cardinality_violation";
87
+ readonly "22000": "data_exception";
88
+ readonly "2202E": "array_subscript_error";
89
+ readonly "22021": "character_not_in_repertoire";
90
+ readonly "22008": "datetime_field_overflow";
91
+ readonly "22012": "division_by_zero";
92
+ readonly "22005": "error_in_assignment";
93
+ readonly "2200B": "escape_character_conflict";
94
+ readonly "22022": "indicator_overflow";
95
+ readonly "22015": "interval_field_overflow";
96
+ readonly "2201E": "invalid_argument_for_logarithm";
97
+ readonly "22014": "invalid_argument_for_ntile_function";
98
+ readonly "22016": "invalid_argument_for_nth_value_function";
99
+ readonly "2201F": "invalid_argument_for_power_function";
100
+ readonly "2201G": "invalid_argument_for_width_bucket_function";
101
+ readonly "22018": "invalid_character_value_for_cast";
102
+ readonly "22007": "invalid_datetime_format";
103
+ readonly "22019": "invalid_escape_character";
104
+ readonly "2200D": "invalid_escape_octet";
105
+ readonly "22025": "invalid_escape_sequence";
106
+ readonly "22P06": "nonstandard_use_of_escape_character";
107
+ readonly "22010": "invalid_indicator_parameter_value";
108
+ readonly "22023": "invalid_parameter_value";
109
+ readonly "22013": "invalid_preceding_or_following_size";
110
+ readonly "2201B": "invalid_regular_expression";
111
+ readonly "2201W": "invalid_row_count_in_limit_clause";
112
+ readonly "2201X": "invalid_row_count_in_result_offset_clause";
113
+ readonly "2202H": "invalid_tablesample_argument";
114
+ readonly "2202G": "invalid_tablesample_repeat";
115
+ readonly "22009": "invalid_time_zone_displacement_value";
116
+ readonly "2200C": "invalid_use_of_escape_character";
117
+ readonly "2200G": "most_specific_type_mismatch";
118
+ readonly "22004": "null_value_not_allowed";
119
+ readonly "22002": "null_value_no_indicator_parameter";
120
+ readonly "22003": "numeric_value_out_of_range";
121
+ readonly "2200H": "sequence_generator_limit_exceeded";
122
+ readonly "22026": "string_data_length_mismatch";
123
+ readonly "22001": "string_data_right_truncation";
124
+ readonly "22011": "substring_error";
125
+ readonly "22027": "trim_error";
126
+ readonly "22024": "unterminated_c_string";
127
+ readonly "2200F": "zero_length_character_string";
128
+ readonly "22P01": "floating_point_exception";
129
+ readonly "22P02": "invalid_text_representation";
130
+ readonly "22P03": "invalid_binary_representation";
131
+ readonly "22P04": "bad_copy_file_format";
132
+ readonly "22P05": "untranslatable_character";
133
+ readonly "2200L": "not_an_xml_document";
134
+ readonly "2200M": "invalid_xml_document";
135
+ readonly "2200N": "invalid_xml_content";
136
+ readonly "2200S": "invalid_xml_comment";
137
+ readonly "2200T": "invalid_xml_processing_instruction";
138
+ readonly "22030": "duplicate_json_object_key_value";
139
+ readonly "22031": "invalid_argument_for_sql_json_datetime_function";
140
+ readonly "22032": "invalid_json_text";
141
+ readonly "22033": "invalid_sql_json_subscript";
142
+ readonly "22034": "more_than_one_sql_json_item";
143
+ readonly "22035": "no_sql_json_item";
144
+ readonly "22036": "non_numeric_sql_json_item";
145
+ readonly "22037": "non_unique_keys_in_a_json_object";
146
+ readonly "22038": "singleton_sql_json_item_required";
147
+ readonly "22039": "sql_json_array_not_found";
148
+ readonly "2203A": "sql_json_member_not_found";
149
+ readonly "2203B": "sql_json_number_not_found";
150
+ readonly "2203C": "sql_json_object_not_found";
151
+ readonly "2203D": "too_many_json_array_elements";
152
+ readonly "2203E": "too_many_json_object_members";
153
+ readonly "2203F": "sql_json_scalar_required";
154
+ readonly "2203G": "sql_json_item_cannot_be_cast_to_target_type";
155
+ readonly "23000": "integrity_constraint_violation";
156
+ readonly "23001": "restrict_violation";
157
+ readonly "23502": "not_null_violation";
158
+ readonly "23503": "foreign_key_violation";
159
+ readonly "23505": "unique_violation";
160
+ readonly "23514": "check_violation";
161
+ readonly "23P01": "exclusion_violation";
162
+ readonly "24000": "invalid_cursor_state";
163
+ readonly "25000": "invalid_transaction_state";
164
+ readonly "25001": "active_sql_transaction";
165
+ readonly "25002": "branch_transaction_already_active";
166
+ readonly "25008": "held_cursor_requires_same_isolation_level";
167
+ readonly "25003": "inappropriate_access_mode_for_branch_transaction";
168
+ readonly "25004": "inappropriate_isolation_level_for_branch_transaction";
169
+ readonly "25005": "no_active_sql_transaction_for_branch_transaction";
170
+ readonly "25006": "read_only_sql_transaction";
171
+ readonly "25007": "schema_and_data_statement_mixing_not_supported";
172
+ readonly "25P01": "no_active_sql_transaction";
173
+ readonly "25P02": "in_failed_sql_transaction";
174
+ readonly "25P03": "idle_in_transaction_session_timeout";
175
+ readonly "25P04": "transaction_timeout";
176
+ readonly "26000": "invalid_sql_statement_name";
177
+ readonly "27000": "triggered_data_change_violation";
178
+ readonly "28000": "invalid_authorization_specification";
179
+ readonly "28P01": "invalid_password";
180
+ readonly "2B000": "dependent_privilege_descriptors_still_exist";
181
+ readonly "2BP01": "dependent_objects_still_exist";
182
+ readonly "2D000": "invalid_transaction_termination";
183
+ readonly "2F000": "sql_routine_exception";
184
+ readonly "2F005": "function_executed_no_return_statement";
185
+ readonly "2F002": "modifying_sql_data_not_permitted";
186
+ readonly "2F003": "prohibited_sql_statement_attempted";
187
+ readonly "2F004": "reading_sql_data_not_permitted";
188
+ readonly "34000": "invalid_cursor_name";
189
+ readonly "38000": "external_routine_exception";
190
+ readonly "38001": "containing_sql_not_permitted";
191
+ readonly "38002": "modifying_sql_data_not_permitted";
192
+ readonly "38003": "prohibited_sql_statement_attempted";
193
+ readonly "38004": "reading_sql_data_not_permitted";
194
+ readonly "39000": "external_routine_invocation_exception";
195
+ readonly "39001": "invalid_sqlstate_returned";
196
+ readonly "39004": "null_value_not_allowed";
197
+ readonly "39P01": "trigger_protocol_violated";
198
+ readonly "39P02": "srf_protocol_violated";
199
+ readonly "39P03": "event_trigger_protocol_violated";
200
+ readonly "3B000": "savepoint_exception";
201
+ readonly "3B001": "invalid_savepoint_specification";
202
+ readonly "3D000": "invalid_catalog_name";
203
+ readonly "3F000": "invalid_schema_name";
204
+ readonly "40000": "transaction_rollback";
205
+ readonly "40002": "transaction_integrity_constraint_violation";
206
+ readonly "40001": "serialization_failure";
207
+ readonly "40003": "statement_completion_unknown";
208
+ readonly "40P01": "deadlock_detected";
209
+ readonly "42000": "syntax_error_or_access_rule_violation";
210
+ readonly "42601": "syntax_error";
211
+ readonly "42501": "insufficient_privilege";
212
+ readonly "42846": "cannot_coerce";
213
+ readonly "42803": "grouping_error";
214
+ readonly "42P20": "windowing_error";
215
+ readonly "42P19": "invalid_recursion";
216
+ readonly "42830": "invalid_foreign_key";
217
+ readonly "42602": "invalid_name";
218
+ readonly "42622": "name_too_long";
219
+ readonly "42939": "reserved_name";
220
+ readonly "42804": "datatype_mismatch";
221
+ readonly "42P18": "indeterminate_datatype";
222
+ readonly "42P21": "collation_mismatch";
223
+ readonly "42P22": "indeterminate_collation";
224
+ readonly "42809": "wrong_object_type";
225
+ readonly "428C9": "generated_always";
226
+ readonly "42703": "undefined_column";
227
+ readonly "42883": "undefined_function";
228
+ readonly "42P01": "undefined_table";
229
+ readonly "42P02": "undefined_parameter";
230
+ readonly "42704": "undefined_object";
231
+ readonly "42701": "duplicate_column";
232
+ readonly "42P03": "duplicate_cursor";
233
+ readonly "42P04": "duplicate_database";
234
+ readonly "42723": "duplicate_function";
235
+ readonly "42P05": "duplicate_prepared_statement";
236
+ readonly "42P06": "duplicate_schema";
237
+ readonly "42P07": "duplicate_table";
238
+ readonly "42712": "duplicate_alias";
239
+ readonly "42710": "duplicate_object";
240
+ readonly "42702": "ambiguous_column";
241
+ readonly "42725": "ambiguous_function";
242
+ readonly "42P08": "ambiguous_parameter";
243
+ readonly "42P09": "ambiguous_alias";
244
+ readonly "42P10": "invalid_column_reference";
245
+ readonly "42611": "invalid_column_definition";
246
+ readonly "42P11": "invalid_cursor_definition";
247
+ readonly "42P12": "invalid_database_definition";
248
+ readonly "42P13": "invalid_function_definition";
249
+ readonly "42P14": "invalid_prepared_statement_definition";
250
+ readonly "42P15": "invalid_schema_definition";
251
+ readonly "42P16": "invalid_table_definition";
252
+ readonly "42P17": "invalid_object_definition";
253
+ readonly "44000": "with_check_option_violation";
254
+ readonly "53000": "insufficient_resources";
255
+ readonly "53100": "disk_full";
256
+ readonly "53200": "out_of_memory";
257
+ readonly "53300": "too_many_connections";
258
+ readonly "53400": "configuration_limit_exceeded";
259
+ readonly "54000": "program_limit_exceeded";
260
+ readonly "54001": "statement_too_complex";
261
+ readonly "54011": "too_many_columns";
262
+ readonly "54023": "too_many_arguments";
263
+ readonly "55000": "object_not_in_prerequisite_state";
264
+ readonly "55006": "object_in_use";
265
+ readonly "55P02": "cant_change_runtime_param";
266
+ readonly "55P03": "lock_not_available";
267
+ readonly "55P04": "unsafe_new_enum_value_usage";
268
+ readonly "57000": "operator_intervention";
269
+ readonly "57014": "query_canceled";
270
+ readonly "57P01": "admin_shutdown";
271
+ readonly "57P02": "crash_shutdown";
272
+ readonly "57P03": "cannot_connect_now";
273
+ readonly "57P04": "database_dropped";
274
+ readonly "57P05": "idle_session_timeout";
275
+ readonly "58000": "system_error";
276
+ readonly "58030": "io_error";
277
+ readonly "58P01": "undefined_file";
278
+ readonly "58P02": "duplicate_file";
279
+ readonly "58P03": "file_name_too_long";
280
+ readonly F0000: "config_file_error";
281
+ readonly F0001: "lock_file_exists";
282
+ readonly HV000: "fdw_error";
283
+ readonly HV005: "fdw_column_name_not_found";
284
+ readonly HV002: "fdw_dynamic_parameter_value_needed";
285
+ readonly HV010: "fdw_function_sequence_error";
286
+ readonly HV021: "fdw_inconsistent_descriptor_information";
287
+ readonly HV024: "fdw_invalid_attribute_value";
288
+ readonly HV007: "fdw_invalid_column_name";
289
+ readonly HV008: "fdw_invalid_column_number";
290
+ readonly HV004: "fdw_invalid_data_type";
291
+ readonly HV006: "fdw_invalid_data_type_descriptors";
292
+ readonly HV091: "fdw_invalid_descriptor_field_identifier";
293
+ readonly HV00B: "fdw_invalid_handle";
294
+ readonly HV00C: "fdw_invalid_option_index";
295
+ readonly HV00D: "fdw_invalid_option_name";
296
+ readonly HV090: "fdw_invalid_string_length_or_buffer_length";
297
+ readonly HV00A: "fdw_invalid_string_format";
298
+ readonly HV009: "fdw_invalid_use_of_null_pointer";
299
+ readonly HV014: "fdw_too_many_handles";
300
+ readonly HV001: "fdw_out_of_memory";
301
+ readonly HV00P: "fdw_no_schemas";
302
+ readonly HV00J: "fdw_option_name_not_found";
303
+ readonly HV00K: "fdw_reply_handle";
304
+ readonly HV00Q: "fdw_schema_not_found";
305
+ readonly HV00R: "fdw_table_not_found";
306
+ readonly HV00L: "fdw_unable_to_create_execution";
307
+ readonly HV00M: "fdw_unable_to_create_reply";
308
+ readonly HV00N: "fdw_unable_to_establish_connection";
309
+ readonly P0000: "plpgsql_error";
310
+ readonly P0001: "raise_exception";
311
+ readonly P0002: "no_data_found";
312
+ readonly P0003: "too_many_rows";
313
+ readonly P0004: "assert_failure";
314
+ readonly XX000: "internal_error";
315
+ readonly XX001: "data_corrupted";
316
+ readonly XX002: "index_corrupted";
317
+ };
318
+ type ConditionsByCode = typeof conditionsByCode;
319
+ /** Name of a condition of PostgreSQL errors, such as `unique_violation`, or of a class of them, such as `integrity_constraint_violation`. */
320
+ type QueryErrorCondition = ConditionsByCode[keyof ConditionsByCode];
321
+ /**
322
+ * SQLSTATE codes of each condition, with every code of its class for the condition of a class.
323
+ *
324
+ * TypeScript computes the map once, whereas a mapped type of the table for each condition would cost a check of another condition about 70 times as many instantiations.
325
+ */
326
+ type CodesByCondition = { [K in keyof ConditionsByCode as ConditionsByCode[K]]: K extends `${infer Class}000` ? `${Class}${string}` : K; };
327
+ /** SQLSTATE codes of the condition `C`, with every code of its class for the condition of a class. */
328
+ type QueryErrorCode<C extends QueryErrorCondition> = CodesByCondition[C];
329
+ /**
330
+ * Tells whether `error` is a `QueryError` of `condition`, including a `QueryError` of another copy of kern-db.
331
+ *
332
+ * The condition of a class, such as `integrity_constraint_violation`, matches every error of its class, as in PL/pgSQL.
333
+ */
334
+ export declare function isQueryError<C extends QueryErrorCondition>(error: unknown, condition: C): error is QueryError & {
335
+ readonly code: QueryErrorCode<C>;
336
+ };
337
+ /** Phase of a transaction in which its connection failed. */
338
+ type TransactionPhase = TransactionConnectionError["phase"];
339
+ /**
340
+ * Error of a transaction whose connection failed, which tells whether the transaction may have been committed.
341
+ *
342
+ * Its `cause` is the error that the transaction would reject with otherwise, such as the error of the callback, or a `SuppressedError` of a failed rollback that keeps it.
343
+ */
344
+ export declare class TransactionConnectionError extends ConnectionError {
345
+ readonly name: string;
346
+ /**
347
+ * Phase of the transaction in which its connection failed:
348
+ *
349
+ * - `begin`: before the callback, such as getting the connection or `BEGIN`, so the transaction applied nothing;
350
+ * - `transaction`: in the callback or its rollback, so the transaction was rolled back;
351
+ * - `commit`: during `COMMIT`, so whether the transaction was committed is unknown.
352
+ */
353
+ readonly phase: "begin" | "transaction" | "commit";
354
+ constructor(phase: TransactionPhase, options?: {
355
+ cause?: unknown;
356
+ });
357
+ /** Tells whether `value` is an instance of the class, including one of `TransactionConnectionError` of another copy of kern-db. */
358
+ static [Symbol.hasInstance]<T>(this: abstract new (...args: never) => T, value: unknown): value is T;
359
+ }
360
+ export { type AcceptedNull, type AcceptedValues, type AnyDerivableType, type AnySqlQuery, type AnyType, type BaseDerivableType, type Connection, type Database, type DatabaseOptions, type DecodedFields, type DerivableType, type DerivableTypeWithParameters, type Driver, type DriverErrorFields, type DriverResult, type FieldTypes, type InitialSqlQueryState, type IsolationLevel, NotFoundError, type OneRow, type OneValueRows, type PollLockOptions, type QueryErrorCode, type QueryErrorCondition, type ResultByRows, ResultDecodeError, type ResultRows, type SessionOptions, type SqlFragment, type SqlQuery, type SqlQueryResult, type SqlQueryState, type SqlStatement, type SqlValue, type TextValue, type TransactionOptions, type Type, type TypeInput, type TypeOptions, type TypeOutput, type TypeTransform, type UntypedValue, type ValueRows, createDatabase, createStatement, defineType, identifier, isDatabase, isDriver, isType, param, sql, type typeValues };
package/dist/index.mjs ADDED
@@ -0,0 +1,5 @@
1
+ import { o as defineType, s as isType } from "./bytea-DNZ_ftio.mjs";
2
+ import { C as isDriver, S as createStatement, _ as sql, h as param, i as ResultDecodeError, m as identifier, r as NotFoundError } from "./query-FKBN7BMY.mjs";
3
+ import { a as toDriverError, n as QueryError, t as ConnectionError } from "./driver-error-26zcdHeU.mjs";
4
+ import { a as TransactionConnectionError, i as isQueryError, r as isDatabase, t as createDatabase } from "./database-BkWPkXG5.mjs";
5
+ export { ConnectionError, NotFoundError, QueryError, ResultDecodeError, TransactionConnectionError, createDatabase, createStatement, defineType, identifier, isDatabase, isDriver, isQueryError, isType, param, sql, toDriverError };
@@ -0,0 +1,8 @@
1
+ import { n as Driver } from "./driver-CSfbXOBJ.mjs";
2
+ import { Pool } from "pg";
3
+ /**
4
+ * Creates a kern-db driver over a node-postgres pool; the pool keeps managing its connections.
5
+ *
6
+ * Closing the driver ends the supplied pool.
7
+ */
8
+ export declare function nodePostgresDriver(pool: Pool): Driver;