data-api-client 2.2.0 → 2.3.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.
- package/README.md +101 -43
- package/dist/compat/index.d.ts +1 -0
- package/dist/compat/index.d.ts.map +1 -1
- package/dist/compat/index.js +4 -1
- package/dist/compat/knex.d.ts +4 -0
- package/dist/compat/knex.d.ts.map +1 -0
- package/dist/compat/knex.js +34 -0
- package/dist/compat/mysql2.d.ts.map +1 -1
- package/dist/compat/mysql2.js +58 -12
- package/dist/compat/pg.d.ts.map +1 -1
- package/dist/compat/pg.js +49 -37
- package/dist/compat/transaction-sql.d.ts +21 -0
- package/dist/compat/transaction-sql.d.ts.map +1 -0
- package/dist/compat/transaction-sql.js +33 -0
- package/package.json +20 -6
package/README.md
CHANGED
|
@@ -3,52 +3,42 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/data-api-client)
|
|
4
4
|
[](https://www.npmjs.com/package/data-api-client)
|
|
5
5
|
|
|
6
|
-
> **Note:** Version 2.1.0 introduces mysql2 and pg compatibility layers with full ORM support! We welcome your feedback and bug reports. Please [open an issue](https://github.com/jeremydaly/data-api-client/issues) if you encounter any problems or have suggestions for improvement.
|
|
7
|
-
>
|
|
8
6
|
> **Using v1.x?** See [README_v1.md](README_v1.md) for v1.x documentation.
|
|
9
7
|
|
|
10
|
-
The **Data API Client** is a lightweight wrapper that
|
|
8
|
+
The **Data API Client** is a lightweight wrapper that makes working with the Amazon Aurora Serverless Data API incredibly easy. The Data API makes you annotate every field value with its type, both going in and coming back, which gets old fast. This library handles that for you, mapping native JavaScript types to the Data API's format and back automatically. It's basically a [DocumentClient](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/DocumentClient.html) for the Data API, with clean **transactions** and **automatic retry logic** for scale-to-zero clusters built in. It also gives you drop-in **compatibility layers** for mysql2 and pg, so you can plug the Data API into your favorite ORMs and query builders. Point **Drizzle**, **Kysely**, or **Knex** at it and keep writing the queries you already know.
|
|
11
9
|
|
|
12
|
-
|
|
10
|
+
For more information about the Aurora Serverless Data API, you can review the [official documentation](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/data-api.html) or read [Aurora Serverless Data API: An (updated) First Look](https://www.jeremydaly.com/aurora-serverless-data-api-a-first-look/) for some more insights on performance.
|
|
13
11
|
|
|
14
|
-
|
|
12
|
+
## What's New in v2.3
|
|
15
13
|
|
|
16
|
-
|
|
14
|
+
- **Knex support**: the `data-api-client/compat/knex` helpers let Knex run on the Data API for both MySQL and PostgreSQL.
|
|
15
|
+
- `createKnexMySQLClient()` and `createKnexPgClient()` return a custom Knex `client` wired to the Data API
|
|
16
|
+
- **Transactions** work: `db.transaction()` commits on success and rolls back when the callback throws. Nested transactions are rejected, since the Data API has no `SAVEPOINT` primitive.
|
|
17
|
+
- The common query-builder surface is covered by integration tests for both engines: selects, the `where` family, joins, aggregates, ordering/pagination, unions, subqueries, CTEs, `insert`/`update`/`del`, `returning`, `increment`/`decrement`, and `onConflict().merge()` upserts
|
|
18
|
+
- `knex` is an optional peer dependency
|
|
19
|
+
- Fixes two latent compatibility-layer bugs that also affected non-Knex callers: pg parameter binding via the config-object callback form, and mysql2 callback parsing
|
|
20
|
+
|
|
21
|
+
See the [Knex section](#knex-query-builder) for usage.
|
|
22
|
+
|
|
23
|
+
## Changelog
|
|
24
|
+
|
|
25
|
+
### v2.2
|
|
26
|
+
|
|
27
|
+
- Dependency updates, including a raised `@aws-sdk/client-rds-data` peer dependency floor
|
|
28
|
+
|
|
29
|
+
### v2.1
|
|
30
|
+
|
|
31
|
+
- **mysql2** and **pg** compatibility layers: drop-in replacements for those drivers, with connection pools, transactions, and both Promise and callback APIs
|
|
32
|
+
- **Automatic retry logic** for Aurora Serverless scale-to-zero wake-ups (`DatabaseResumingException` and transient connection errors), configurable and enabled by default
|
|
33
|
+
- Verified ORM support for **Drizzle** and **Kysely**
|
|
17
34
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
-
|
|
25
|
-
- Full support for connection pools and transactions
|
|
26
|
-
- Works seamlessly with ORMs like Drizzle and Kysely
|
|
27
|
-
- **pg Compatibility Layer**: Drop-in replacement for the `pg` (node-postgres) library
|
|
28
|
-
- Promise-based and callback-based APIs
|
|
29
|
-
- Compatible with ORMs and query builders
|
|
30
|
-
- **ORM Support**: Tested and verified with popular ORMs:
|
|
31
|
-
- **Drizzle ORM**: Full support for both MySQL and PostgreSQL
|
|
32
|
-
- **Kysely**: Query builder support for both engines
|
|
33
|
-
|
|
34
|
-
## What's New in v2.0
|
|
35
|
-
|
|
36
|
-
- **AWS SDK v3**: Migrated from AWS SDK v2 to v3 for smaller bundle sizes and better tree-shaking
|
|
37
|
-
- **TypeScript**: Full TypeScript implementation with comprehensive type definitions
|
|
38
|
-
- **PostgreSQL Array Support**: Automatic conversion of PostgreSQL arrays to native JavaScript arrays in query results
|
|
39
|
-
- **Comprehensive Data Type Coverage**: Extensive support for PostgreSQL data types including:
|
|
40
|
-
- All numeric types (SMALLINT, INT, BIGINT, DECIMAL, NUMERIC, REAL, DOUBLE PRECISION)
|
|
41
|
-
- String types (CHAR, VARCHAR, TEXT)
|
|
42
|
-
- Boolean, Date/Time types (DATE, TIME, TIMESTAMP, TIMESTAMPTZ)
|
|
43
|
-
- Binary data (BYTEA)
|
|
44
|
-
- JSON and JSONB with nested structures
|
|
45
|
-
- UUID with type casting support
|
|
46
|
-
- Network types (INET, CIDR)
|
|
47
|
-
- Range types (INT4RANGE, NUMRANGE, TSTZRANGE)
|
|
48
|
-
- Arrays of all supported types
|
|
49
|
-
- **Modern Build System**: TypeScript compilation with ES6+ output
|
|
50
|
-
- **Enhanced Type Casting**: Improved support for PostgreSQL type casting with inline (`::type`) and parameter-based casting
|
|
51
|
-
- **Better Error Handling**: More informative error messages and validation
|
|
35
|
+
### v2.0
|
|
36
|
+
|
|
37
|
+
- Migrated to **AWS SDK v3** for smaller bundles and better tree-shaking
|
|
38
|
+
- Full **TypeScript** implementation with comprehensive type definitions
|
|
39
|
+
- **PostgreSQL array** results automatically converted to native JavaScript arrays
|
|
40
|
+
- Comprehensive PostgreSQL data type coverage: numeric, string, boolean, date/time, `BYTEA`, JSON/JSONB, UUID, network (INET/CIDR), range, and arrays of all supported types
|
|
41
|
+
- Inline (`::type`) and parameter-based type casting, with more informative error messages
|
|
52
42
|
|
|
53
43
|
## Simple Examples
|
|
54
44
|
|
|
@@ -197,7 +187,7 @@ The AWS Data API offers a [built-in JSON format option](https://docs.aws.amazon.
|
|
|
197
187
|
|
|
198
188
|
**No Additional Limitations:** AWS's JSON support requires unique column names and has a 10MB response limit. The Data API Client works with any column configuration and imposes no additional size restrictions.
|
|
199
189
|
|
|
200
|
-
|
|
190
|
+
AWS's JSON support is a basic convenience feature. The **Data API Client** provides true type intelligence, format flexibility, and seamless handling of complex PostgreSQL features that the native Data API doesn't support well.
|
|
201
191
|
|
|
202
192
|
## Installation and Setup
|
|
203
193
|
|
|
@@ -855,10 +845,78 @@ const db = new Kysely<Database>({
|
|
|
855
845
|
const users = await db.selectFrom('users').selectAll().where('id', '=', 123).execute()
|
|
856
846
|
```
|
|
857
847
|
|
|
848
|
+
#### Knex Query Builder
|
|
849
|
+
|
|
850
|
+
Knex doesn't accept an injected pool like Drizzle and Kysely. It constructs its own
|
|
851
|
+
driver internally, so the `data-api-client/compat/knex` helpers return a custom Knex
|
|
852
|
+
`client` class wired to the Data API, which you pass as `client`:
|
|
853
|
+
|
|
854
|
+
**MySQL with Knex:**
|
|
855
|
+
|
|
856
|
+
```typescript
|
|
857
|
+
import knex from 'knex'
|
|
858
|
+
import { createKnexMySQLClient } from 'data-api-client/compat/knex'
|
|
859
|
+
|
|
860
|
+
const db = knex({
|
|
861
|
+
client: createKnexMySQLClient({
|
|
862
|
+
resourceArn: 'arn:...',
|
|
863
|
+
secretArn: 'arn:...',
|
|
864
|
+
database: 'myDatabase'
|
|
865
|
+
}),
|
|
866
|
+
connection: {}
|
|
867
|
+
})
|
|
868
|
+
|
|
869
|
+
// Use Knex normally
|
|
870
|
+
const users = await db('users').where('id', 123).select('*')
|
|
871
|
+
```
|
|
872
|
+
|
|
873
|
+
**PostgreSQL with Knex:**
|
|
874
|
+
|
|
875
|
+
```typescript
|
|
876
|
+
import knex from 'knex'
|
|
877
|
+
import { createKnexPgClient } from 'data-api-client/compat/knex'
|
|
878
|
+
|
|
879
|
+
const db = knex({
|
|
880
|
+
client: createKnexPgClient({
|
|
881
|
+
resourceArn: 'arn:...',
|
|
882
|
+
secretArn: 'arn:...',
|
|
883
|
+
database: 'myDatabase'
|
|
884
|
+
}),
|
|
885
|
+
connection: {}
|
|
886
|
+
})
|
|
887
|
+
|
|
888
|
+
// Use Knex normally
|
|
889
|
+
const id = await db('users').insert({ name: 'Alice' }).returning('id')
|
|
890
|
+
```
|
|
891
|
+
|
|
892
|
+
> **Note:** `knex` is an optional peer dependency. Install it alongside `data-api-client`
|
|
893
|
+
> to use these helpers.
|
|
894
|
+
|
|
895
|
+
Knex transactions work. The compat layer intercepts the `BEGIN`/`COMMIT`/`ROLLBACK`
|
|
896
|
+
SQL that Knex issues and maps it to the Data API transaction lifecycle:
|
|
897
|
+
|
|
898
|
+
```typescript
|
|
899
|
+
await db.transaction(async (trx) => {
|
|
900
|
+
const [userId] = await trx('users').insert({ name: 'Alice' }).returning('id')
|
|
901
|
+
await trx('posts').insert({ user_id: userId, title: 'Hello' })
|
|
902
|
+
}) // commits on success, rolls back if the callback throws
|
|
903
|
+
```
|
|
904
|
+
|
|
905
|
+
> **Nested transactions are not supported.** They require SQL `SAVEPOINT`s, which the RDS
|
|
906
|
+
> Data API has no primitive for, so a nested `trx.transaction(...)` throws. A single
|
|
907
|
+
> top-level transaction works as shown above.
|
|
908
|
+
|
|
909
|
+
The common query-builder syntax is covered by integration tests for both engines:
|
|
910
|
+
selects/`distinct`/`pluck`/`first`, the `where` family (`whereIn`, `whereNull`,
|
|
911
|
+
`whereBetween`, `whereExists`, `whereRaw`, and so on), joins, `groupBy`/`having`/aggregates,
|
|
912
|
+
`orderBy`/`limit`/`offset`, unions, subqueries, CTEs (`with`), `insert`/`update`/`del`,
|
|
913
|
+
`returning` (PostgreSQL), `increment`/`decrement`, and `onConflict().merge()` upserts.
|
|
914
|
+
Streaming via `.stream()` is not supported, since the Data API has no cursor API.
|
|
915
|
+
|
|
858
916
|
**Benefits of Compatibility Layers:**
|
|
859
917
|
|
|
860
918
|
- **Zero code changes** when migrating from mysql2 or pg
|
|
861
|
-
- **Full ORM support** (Drizzle, Kysely)
|
|
919
|
+
- **Full ORM support** (Drizzle, Kysely, Knex)
|
|
862
920
|
- **Automatic retry logic** for cluster wake-ups
|
|
863
921
|
- **Connection pooling simulation** (getConnection, release)
|
|
864
922
|
- **Both Promise and callback APIs** supported
|
|
@@ -919,7 +977,7 @@ await data.query('INSERT INTO products (tags) VALUES (ARRAY[:tag1, :tag2, :tag3]
|
|
|
919
977
|
})
|
|
920
978
|
```
|
|
921
979
|
|
|
922
|
-
Despite these input limitations, **all array results are automatically converted to native JavaScript arrays**, making it easy to work with PostgreSQL array data in your application. `NULL` elements inside arrays round-trip correctly
|
|
980
|
+
Despite these input limitations, **all array results are automatically converted to native JavaScript arrays**, making it easy to work with PostgreSQL array data in your application. `NULL` elements inside arrays round-trip correctly. For example, `'{1,NULL,3}'::int[]` deserializes to `[1, null, 3]`.
|
|
923
981
|
|
|
924
982
|
## PostgreSQL Data Type Support
|
|
925
983
|
|
package/dist/compat/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export { createPgClient, createPgPool } from './pg';
|
|
|
2
2
|
export type { PgCompatClient, PgCompatPool, PgQueryResult } from './pg';
|
|
3
3
|
export { createMySQLConnection, createMySQLPool } from './mysql2';
|
|
4
4
|
export type { Connection, Pool, PoolConnection, MySQL2QueryResult } from './mysql2';
|
|
5
|
+
export { createKnexMySQLClient, createKnexPgClient } from './knex';
|
|
5
6
|
export { mapToPostgresError, mapToMySQLError } from './errors';
|
|
6
7
|
export type { PostgresError, MySQLError } from './errors';
|
|
7
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/compat/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/compat/index.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AACnD,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,MAAM,CAAA;AAEvE,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AACjE,YAAY,EAAE,UAAU,EAAE,IAAI,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAA;AAEnF,OAAO,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAA;AAElE,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAC9D,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA"}
|
package/dist/compat/index.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mapToMySQLError = exports.mapToPostgresError = exports.createMySQLPool = exports.createMySQLConnection = exports.createPgPool = exports.createPgClient = void 0;
|
|
3
|
+
exports.mapToMySQLError = exports.mapToPostgresError = exports.createKnexPgClient = exports.createKnexMySQLClient = exports.createMySQLPool = exports.createMySQLConnection = exports.createPgPool = exports.createPgClient = void 0;
|
|
4
4
|
var pg_1 = require("./pg");
|
|
5
5
|
Object.defineProperty(exports, "createPgClient", { enumerable: true, get: function () { return pg_1.createPgClient; } });
|
|
6
6
|
Object.defineProperty(exports, "createPgPool", { enumerable: true, get: function () { return pg_1.createPgPool; } });
|
|
7
7
|
var mysql2_1 = require("./mysql2");
|
|
8
8
|
Object.defineProperty(exports, "createMySQLConnection", { enumerable: true, get: function () { return mysql2_1.createMySQLConnection; } });
|
|
9
9
|
Object.defineProperty(exports, "createMySQLPool", { enumerable: true, get: function () { return mysql2_1.createMySQLPool; } });
|
|
10
|
+
var knex_1 = require("./knex");
|
|
11
|
+
Object.defineProperty(exports, "createKnexMySQLClient", { enumerable: true, get: function () { return knex_1.createKnexMySQLClient; } });
|
|
12
|
+
Object.defineProperty(exports, "createKnexPgClient", { enumerable: true, get: function () { return knex_1.createKnexPgClient; } });
|
|
10
13
|
var errors_1 = require("./errors");
|
|
11
14
|
Object.defineProperty(exports, "mapToPostgresError", { enumerable: true, get: function () { return errors_1.mapToPostgresError; } });
|
|
12
15
|
Object.defineProperty(exports, "mapToMySQLError", { enumerable: true, get: function () { return errors_1.mapToMySQLError; } });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"knex.d.ts","sourceRoot":"","sources":["../../src/compat/knex.ts"],"names":[],"mappings":"AAgCA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;AAMnD,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAyB1E;AAMD,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAmBvE"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createKnexMySQLClient = createKnexMySQLClient;
|
|
4
|
+
exports.createKnexPgClient = createKnexPgClient;
|
|
5
|
+
const mysql2_1 = require("./mysql2");
|
|
6
|
+
const pg_1 = require("./pg");
|
|
7
|
+
function createKnexMySQLClient(config) {
|
|
8
|
+
const Client_MySQL2 = require('knex/lib/dialects/mysql2');
|
|
9
|
+
return class DataApiKnexMySQLClient extends Client_MySQL2 {
|
|
10
|
+
_driver() {
|
|
11
|
+
return {
|
|
12
|
+
createConnection: () => {
|
|
13
|
+
const conn = (0, mysql2_1.createMySQLConnection)(config);
|
|
14
|
+
if (!conn.stream) {
|
|
15
|
+
conn.stream = { destroyed: false };
|
|
16
|
+
}
|
|
17
|
+
return conn;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function createKnexPgClient(config) {
|
|
24
|
+
const Client_PG = require('knex/lib/dialects/postgres');
|
|
25
|
+
return class DataApiKnexPgClient extends Client_PG {
|
|
26
|
+
_driver() {
|
|
27
|
+
return {
|
|
28
|
+
Client: function DataApiPgClient() {
|
|
29
|
+
return (0, pg_1.createPgClient)(config);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mysql2.d.ts","sourceRoot":"","sources":["../../src/compat/mysql2.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AAGrC,OAAO,KAAK,EAAE,mBAAmB,EAAoD,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"mysql2.d.ts","sourceRoot":"","sources":["../../src/compat/mysql2.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AAGrC,OAAO,KAAK,EAAE,mBAAmB,EAAoD,MAAM,UAAU,CAAA;AAQrG,MAAM,WAAW,cAAe,SAAQ,UAAU;IAChD,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;CACrB;AAED,MAAM,WAAW,UAAW,SAAQ,YAAY;IAC9C,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,KAAK,GAAG,IAAI,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAC9D,GAAG,CAAC,QAAQ,CAAC,EAAE,C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/compat/mysql2.js
CHANGED
|
@@ -9,6 +9,7 @@ const events_1 = require("events");
|
|
|
9
9
|
const sqlstring_1 = __importDefault(require("sqlstring"));
|
|
10
10
|
const client_1 = require("../client");
|
|
11
11
|
const errors_1 = require("./errors");
|
|
12
|
+
const transaction_sql_1 = require("./transaction-sql");
|
|
12
13
|
function formatMySQLQuery(sql, params = []) {
|
|
13
14
|
return sqlstring_1.default.format(sql, params);
|
|
14
15
|
}
|
|
@@ -72,6 +73,10 @@ function createMySQLConnection(config) {
|
|
|
72
73
|
const eventEmitter = new events_1.EventEmitter();
|
|
73
74
|
let transactionId;
|
|
74
75
|
async function executeQuery(sqlOrOptions, params) {
|
|
76
|
+
const rawSql = typeof sqlOrOptions === 'string' ? sqlOrOptions : sqlOrOptions.sql;
|
|
77
|
+
const txControl = await runTransactionControl(rawSql);
|
|
78
|
+
if (txControl)
|
|
79
|
+
return txControl;
|
|
75
80
|
let sql;
|
|
76
81
|
let values = [];
|
|
77
82
|
let rowsAsArray = false;
|
|
@@ -107,6 +112,39 @@ function createMySQLConnection(config) {
|
|
|
107
112
|
const result = await core.query(queryOptions);
|
|
108
113
|
return convertToMySQL2Result(result, sql);
|
|
109
114
|
}
|
|
115
|
+
async function runTransactionControl(sql) {
|
|
116
|
+
const txn = (0, transaction_sql_1.classifyTransactionControl)(sql);
|
|
117
|
+
if (!txn)
|
|
118
|
+
return null;
|
|
119
|
+
const empty = [[], undefined];
|
|
120
|
+
switch (txn.kind) {
|
|
121
|
+
case 'begin': {
|
|
122
|
+
const txResult = await core.beginTransaction();
|
|
123
|
+
transactionId = txResult.transactionId;
|
|
124
|
+
return empty;
|
|
125
|
+
}
|
|
126
|
+
case 'commit': {
|
|
127
|
+
if (transactionId) {
|
|
128
|
+
await core.commitTransaction({ transactionId });
|
|
129
|
+
transactionId = undefined;
|
|
130
|
+
}
|
|
131
|
+
return empty;
|
|
132
|
+
}
|
|
133
|
+
case 'rollback': {
|
|
134
|
+
if (transactionId) {
|
|
135
|
+
await core.rollbackTransaction({ transactionId });
|
|
136
|
+
transactionId = undefined;
|
|
137
|
+
}
|
|
138
|
+
return empty;
|
|
139
|
+
}
|
|
140
|
+
case 'setTransaction':
|
|
141
|
+
return empty;
|
|
142
|
+
case 'savepoint':
|
|
143
|
+
case 'release':
|
|
144
|
+
case 'rollbackTo':
|
|
145
|
+
throw new Error(transaction_sql_1.NESTED_TRANSACTION_MESSAGE);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
110
148
|
const connection = Object.assign(eventEmitter, {
|
|
111
149
|
connect(callback) {
|
|
112
150
|
if (callback) {
|
|
@@ -137,9 +175,11 @@ function createMySQLConnection(config) {
|
|
|
137
175
|
if (typeof paramsOrCallback === 'function') {
|
|
138
176
|
cb = paramsOrCallback;
|
|
139
177
|
}
|
|
140
|
-
else
|
|
141
|
-
|
|
142
|
-
|
|
178
|
+
else {
|
|
179
|
+
if (paramsOrCallback !== undefined && paramsOrCallback !== null) {
|
|
180
|
+
params = paramsOrCallback;
|
|
181
|
+
}
|
|
182
|
+
if (typeof callback === 'function') {
|
|
143
183
|
cb = callback;
|
|
144
184
|
}
|
|
145
185
|
}
|
|
@@ -148,9 +188,11 @@ function createMySQLConnection(config) {
|
|
|
148
188
|
if (typeof paramsOrCallback === 'function') {
|
|
149
189
|
cb = paramsOrCallback;
|
|
150
190
|
}
|
|
151
|
-
else
|
|
152
|
-
|
|
153
|
-
|
|
191
|
+
else {
|
|
192
|
+
if (paramsOrCallback !== undefined && paramsOrCallback !== null) {
|
|
193
|
+
params = paramsOrCallback;
|
|
194
|
+
}
|
|
195
|
+
if (typeof callback === 'function') {
|
|
154
196
|
cb = callback;
|
|
155
197
|
}
|
|
156
198
|
}
|
|
@@ -340,9 +382,11 @@ function createMySQLPool(config) {
|
|
|
340
382
|
if (typeof paramsOrCallback === 'function') {
|
|
341
383
|
cb = paramsOrCallback;
|
|
342
384
|
}
|
|
343
|
-
else
|
|
344
|
-
|
|
345
|
-
|
|
385
|
+
else {
|
|
386
|
+
if (paramsOrCallback !== undefined && paramsOrCallback !== null) {
|
|
387
|
+
params = paramsOrCallback;
|
|
388
|
+
}
|
|
389
|
+
if (typeof callback === 'function') {
|
|
346
390
|
cb = callback;
|
|
347
391
|
}
|
|
348
392
|
}
|
|
@@ -351,9 +395,11 @@ function createMySQLPool(config) {
|
|
|
351
395
|
if (typeof paramsOrCallback === 'function') {
|
|
352
396
|
cb = paramsOrCallback;
|
|
353
397
|
}
|
|
354
|
-
else
|
|
355
|
-
|
|
356
|
-
|
|
398
|
+
else {
|
|
399
|
+
if (paramsOrCallback !== undefined && paramsOrCallback !== null) {
|
|
400
|
+
params = paramsOrCallback;
|
|
401
|
+
}
|
|
402
|
+
if (typeof callback === 'function') {
|
|
357
403
|
cb = callback;
|
|
358
404
|
}
|
|
359
405
|
}
|
package/dist/compat/pg.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pg.d.ts","sourceRoot":"","sources":["../../src/compat/pg.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AAGrC,OAAO,KAAK,EAAE,mBAAmB,EAAoD,MAAM,UAAU,CAAA;AACrG,OAAO,EAAsB,KAAK,aAAa,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"pg.d.ts","sourceRoot":"","sources":["../../src/compat/pg.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AAGrC,OAAO,KAAK,EAAE,mBAAmB,EAAoD,MAAM,UAAU,CAAA;AACrG,OAAO,EAAsB,KAAK,aAAa,EAAE,MAAM,UAAU,CAAA;AAIjE,MAAM,WAAW,aAAa,CAAC,CAAC,GAAG,GAAG;IACpC,IAAI,EAAE,CAAC,EAAE,CAAA;IACT,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,EAAE,KAAK,CAAC;QAAE,IAAI,E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AK,EAAE,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,KAAK,IAAI,GACvD,IAAI,CAAA;IACP,KAAK,CAAC,CAAC,GAAG,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE,QAAQ,EAAE,CAAC,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,KAAK,IAAI,GAAG,IAAI,CAAA;IAGhH,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,GAAG,EAAE,aAAa,KAAK,IAAI,GAAG,IAAI,CAAA;IAChE,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,MAAM,EAAE,cAAc,KAAK,IAAI,GAAG,IAAI,CAAA;IACtE,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,MAAM,EAAE,cAAc,KAAK,IAAI,GAAG,IAAI,CAAA;IACtE,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,MAAM,EAAE,cAAc,KAAK,IAAI,GAAG,IAAI,CAAA;IACrE,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,GAAG,IAAI,CAAA;CAC5D;AAqHD,wBAAgB,cAAc,CAAC,MAAM,EAAE,mBAAmB,GAAG,cAAc,CAiN1E;AASD,wBAAgB,YAAY,CAAC,MAAM,EAAE,mBAAmB,GAAG,YAAY,CAmKtE"}
|
package/dist/compat/pg.js
CHANGED
|
@@ -39,6 +39,7 @@ const events_1 = require("events");
|
|
|
39
39
|
const pgEscape = __importStar(require("../pg-escape"));
|
|
40
40
|
const client_1 = require("../client");
|
|
41
41
|
const errors_1 = require("./errors");
|
|
42
|
+
const transaction_sql_1 = require("./transaction-sql");
|
|
42
43
|
function convertPgPlaceholders(sql, params = []) {
|
|
43
44
|
const namedParams = {};
|
|
44
45
|
const convertedSql = sql.replace(/\$(\d+)/g, (match, index) => {
|
|
@@ -54,7 +55,6 @@ function convertPgPlaceholders(sql, params = []) {
|
|
|
54
55
|
}
|
|
55
56
|
function inferCommand(sql) {
|
|
56
57
|
var _a;
|
|
57
|
-
const match = (_a = sql.trim().split(/\s+/)[0]) === null || _a === void 0 ? void 0 : _a.toUpperCase();
|
|
58
58
|
const knownCommands = [
|
|
59
59
|
'SELECT',
|
|
60
60
|
'INSERT',
|
|
@@ -67,7 +67,23 @@ function inferCommand(sql) {
|
|
|
67
67
|
'GRANT',
|
|
68
68
|
'REVOKE'
|
|
69
69
|
];
|
|
70
|
-
|
|
70
|
+
const first = (_a = sql.trim().split(/\s+/)[0]) === null || _a === void 0 ? void 0 : _a.toUpperCase();
|
|
71
|
+
if (first && knownCommands.includes(first))
|
|
72
|
+
return first;
|
|
73
|
+
if (first === 'WITH') {
|
|
74
|
+
let depth = 0;
|
|
75
|
+
const re = /\(|\)|\b(SELECT|INSERT|UPDATE|DELETE)\b/gi;
|
|
76
|
+
let m;
|
|
77
|
+
while ((m = re.exec(sql)) !== null) {
|
|
78
|
+
if (m[0] === '(')
|
|
79
|
+
depth++;
|
|
80
|
+
else if (m[0] === ')')
|
|
81
|
+
depth--;
|
|
82
|
+
else if (depth === 0)
|
|
83
|
+
return m[1].toUpperCase();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return 'QUERY';
|
|
71
87
|
}
|
|
72
88
|
function convertToPgResult(result, sql, rowMode) {
|
|
73
89
|
if (result.records && Array.isArray(result.records)) {
|
|
@@ -136,40 +152,36 @@ function createPgClient(config) {
|
|
|
136
152
|
values = params !== undefined ? params : sqlOrConfig.values || [];
|
|
137
153
|
rowMode = sqlOrConfig.rowMode;
|
|
138
154
|
}
|
|
139
|
-
const
|
|
140
|
-
if (
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
155
|
+
const txn = (0, transaction_sql_1.classifyTransactionControl)(sql);
|
|
156
|
+
if (txn) {
|
|
157
|
+
const empty = (command) => ({ rows: [], rowCount: 0, command, fields: [] });
|
|
158
|
+
switch (txn.kind) {
|
|
159
|
+
case 'begin': {
|
|
160
|
+
const txResult = await core.beginTransaction();
|
|
161
|
+
transactionId = txResult.transactionId;
|
|
162
|
+
return empty('BEGIN');
|
|
163
|
+
}
|
|
164
|
+
case 'commit': {
|
|
165
|
+
if (transactionId) {
|
|
166
|
+
await core.commitTransaction({ transactionId });
|
|
167
|
+
transactionId = undefined;
|
|
168
|
+
}
|
|
169
|
+
return empty('COMMIT');
|
|
170
|
+
}
|
|
171
|
+
case 'rollback': {
|
|
172
|
+
if (transactionId) {
|
|
173
|
+
await core.rollbackTransaction({ transactionId });
|
|
174
|
+
transactionId = undefined;
|
|
175
|
+
}
|
|
176
|
+
return empty('ROLLBACK');
|
|
177
|
+
}
|
|
178
|
+
case 'setTransaction':
|
|
179
|
+
return empty('SET');
|
|
180
|
+
case 'savepoint':
|
|
181
|
+
case 'release':
|
|
182
|
+
case 'rollbackTo':
|
|
183
|
+
throw new Error(transaction_sql_1.NESTED_TRANSACTION_MESSAGE);
|
|
166
184
|
}
|
|
167
|
-
return {
|
|
168
|
-
rows: [],
|
|
169
|
-
rowCount: 0,
|
|
170
|
-
command: 'ROLLBACK',
|
|
171
|
-
fields: []
|
|
172
|
-
};
|
|
173
185
|
}
|
|
174
186
|
const { sql: convertedSql, params: namedParams } = convertPgPlaceholders(sql, values);
|
|
175
187
|
const queryOptions = {
|
|
@@ -224,7 +236,7 @@ function createPgClient(config) {
|
|
|
224
236
|
if (typeof sqlOrConfig === 'object' && 'submit' in sqlOrConfig) {
|
|
225
237
|
throw new Error('Query streams are not supported by RDS Data API');
|
|
226
238
|
}
|
|
227
|
-
let params
|
|
239
|
+
let params;
|
|
228
240
|
let cb;
|
|
229
241
|
if (typeof sqlOrConfig === 'object' && 'text' in sqlOrConfig) {
|
|
230
242
|
if (typeof paramsOrCallback === 'function') {
|
|
@@ -344,7 +356,7 @@ function createPgPool(config) {
|
|
|
344
356
|
if (typeof sqlOrConfig === 'object' && 'submit' in sqlOrConfig) {
|
|
345
357
|
throw new Error('Query streams are not supported by RDS Data API');
|
|
346
358
|
}
|
|
347
|
-
let params
|
|
359
|
+
let params;
|
|
348
360
|
let cb;
|
|
349
361
|
if (typeof sqlOrConfig === 'object' && 'text' in sqlOrConfig) {
|
|
350
362
|
if (typeof paramsOrCallback === 'function') {
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export type TransactionControl = {
|
|
2
|
+
kind: 'begin';
|
|
3
|
+
} | {
|
|
4
|
+
kind: 'commit';
|
|
5
|
+
} | {
|
|
6
|
+
kind: 'rollback';
|
|
7
|
+
} | {
|
|
8
|
+
kind: 'setTransaction';
|
|
9
|
+
} | {
|
|
10
|
+
kind: 'savepoint';
|
|
11
|
+
name: string;
|
|
12
|
+
} | {
|
|
13
|
+
kind: 'release';
|
|
14
|
+
name: string;
|
|
15
|
+
} | {
|
|
16
|
+
kind: 'rollbackTo';
|
|
17
|
+
name: string;
|
|
18
|
+
};
|
|
19
|
+
export declare const classifyTransactionControl: (sql: string) => TransactionControl | null;
|
|
20
|
+
export declare const NESTED_TRANSACTION_MESSAGE: string;
|
|
21
|
+
//# sourceMappingURL=transaction-sql.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction-sql.d.ts","sourceRoot":"","sources":["../../src/compat/transaction-sql.ts"],"names":[],"mappings":"AAcA,MAAM,MAAM,kBAAkB,GAC1B;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,GACjB;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,GAClB;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,GACpB;IAAE,IAAI,EAAE,gBAAgB,CAAA;CAAE,GAC1B;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACnC;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACjC;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAA;AAexC,eAAO,MAAM,0BAA0B,GAAI,KAAK,MAAM,KAAG,kBAAkB,GAAG,IAwB7E,CAAA;AAGD,eAAO,MAAM,0BAA0B,QAEA,CAAA"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NESTED_TRANSACTION_MESSAGE = exports.classifyTransactionControl = void 0;
|
|
4
|
+
const normalize = (sql) => sql
|
|
5
|
+
.trim()
|
|
6
|
+
.replace(/;\s*$/, '')
|
|
7
|
+
.replace(/\s+/g, ' ')
|
|
8
|
+
.toUpperCase();
|
|
9
|
+
const classifyTransactionControl = (sql) => {
|
|
10
|
+
const n = normalize(sql);
|
|
11
|
+
if (n === 'BEGIN' || n.startsWith('BEGIN ') || n.startsWith('BEGIN TRANSACTION') || n.startsWith('START TRANSACTION')) {
|
|
12
|
+
return { kind: 'begin' };
|
|
13
|
+
}
|
|
14
|
+
if (n === 'COMMIT' || n === 'COMMIT WORK')
|
|
15
|
+
return { kind: 'commit' };
|
|
16
|
+
if (n === 'ROLLBACK' || n === 'ROLLBACK WORK')
|
|
17
|
+
return { kind: 'rollback' };
|
|
18
|
+
const savepoint = n.match(/^SAVEPOINT (.+)$/);
|
|
19
|
+
if (savepoint)
|
|
20
|
+
return { kind: 'savepoint', name: savepoint[1] };
|
|
21
|
+
const release = n.match(/^RELEASE SAVEPOINT (.+)$/);
|
|
22
|
+
if (release)
|
|
23
|
+
return { kind: 'release', name: release[1] };
|
|
24
|
+
const rollbackTo = n.match(/^ROLLBACK TO SAVEPOINT (.+)$/);
|
|
25
|
+
if (rollbackTo)
|
|
26
|
+
return { kind: 'rollbackTo', name: rollbackTo[1] };
|
|
27
|
+
if (n.startsWith('SET TRANSACTION'))
|
|
28
|
+
return { kind: 'setTransaction' };
|
|
29
|
+
return null;
|
|
30
|
+
};
|
|
31
|
+
exports.classifyTransactionControl = classifyTransactionControl;
|
|
32
|
+
exports.NESTED_TRANSACTION_MESSAGE = 'Nested transactions (SAVEPOINT) are not supported over the RDS Data API. ' +
|
|
33
|
+
'Use a single top-level transaction.';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "data-api-client",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "A lightweight wrapper that simplifies working with the Amazon Aurora Serverless Data API",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -20,6 +20,11 @@
|
|
|
20
20
|
"import": "./dist/compat/mysql2.js",
|
|
21
21
|
"require": "./dist/compat/mysql2.js"
|
|
22
22
|
},
|
|
23
|
+
"./compat/knex": {
|
|
24
|
+
"types": "./dist/compat/knex.d.ts",
|
|
25
|
+
"import": "./dist/compat/knex.js",
|
|
26
|
+
"require": "./dist/compat/knex.js"
|
|
27
|
+
},
|
|
23
28
|
"./compat": {
|
|
24
29
|
"types": "./dist/compat/index.d.ts",
|
|
25
30
|
"import": "./dist/compat/index.js",
|
|
@@ -49,7 +54,9 @@
|
|
|
49
54
|
"test:int:orm:drizzle": "npm run build && vitest run integration-tests/drizzle-pg.int.test.ts && vitest run integration-tests/drizzle-mysql.int.test.ts",
|
|
50
55
|
"test:int:orm:drizzle:pg": "npm run build && vitest run integration-tests/drizzle-pg.int.test.ts",
|
|
51
56
|
"test:int:orm:drizzle:mysql": "npm run build && vitest run integration-tests/drizzle-mysql.int.test.ts",
|
|
52
|
-
"test:int:orm:knex": "npm run build && vitest run integration-tests/knex-mysql.int.test.ts",
|
|
57
|
+
"test:int:orm:knex": "npm run build && vitest run integration-tests/knex-mysql.int.test.ts integration-tests/knex-pg.int.test.ts integration-tests/knex-mysql-querybuilder.int.test.ts integration-tests/knex-pg-querybuilder.int.test.ts",
|
|
58
|
+
"test:int:orm:knex:pg": "npm run build && vitest run integration-tests/knex-pg.int.test.ts integration-tests/knex-pg-querybuilder.int.test.ts",
|
|
59
|
+
"test:int:orm:knex:mysql": "npm run build && vitest run integration-tests/knex-mysql.int.test.ts integration-tests/knex-mysql-querybuilder.int.test.ts",
|
|
53
60
|
"test-ci": "npm run build && eslint src && vitest run src/",
|
|
54
61
|
"lint": "eslint src",
|
|
55
62
|
"prepublishOnly": "npm run build"
|
|
@@ -80,7 +87,7 @@
|
|
|
80
87
|
"@types/sqlstring": "^2.3.2",
|
|
81
88
|
"@typescript-eslint/eslint-plugin": "^8.45.0",
|
|
82
89
|
"@typescript-eslint/parser": "^8.45.0",
|
|
83
|
-
"@vitest/ui": "^
|
|
90
|
+
"@vitest/ui": "^4.1.8",
|
|
84
91
|
"drizzle-orm": "^0.45.2",
|
|
85
92
|
"eslint": "^8.12.0",
|
|
86
93
|
"eslint-config-prettier": "^8.5.0",
|
|
@@ -90,20 +97,27 @@
|
|
|
90
97
|
"prettier": "^2.6.2",
|
|
91
98
|
"tsx": "^4.20.6",
|
|
92
99
|
"typescript": "^5.9.3",
|
|
93
|
-
"vitest": "^
|
|
100
|
+
"vitest": "^4.1.8"
|
|
94
101
|
},
|
|
95
102
|
"dependencies": {
|
|
96
103
|
"sqlstring": "^2.3.2"
|
|
97
104
|
},
|
|
98
105
|
"peerDependencies": {
|
|
99
|
-
"@aws-sdk/client-rds-data": "^3.1048.0"
|
|
106
|
+
"@aws-sdk/client-rds-data": "^3.1048.0",
|
|
107
|
+
"knex": "^3.0.0"
|
|
100
108
|
},
|
|
101
109
|
"peerDependenciesMeta": {
|
|
102
110
|
"@aws-sdk/client-rds-data": {
|
|
103
111
|
"optional": true
|
|
112
|
+
},
|
|
113
|
+
"knex": {
|
|
114
|
+
"optional": true
|
|
104
115
|
}
|
|
105
116
|
},
|
|
106
117
|
"files": [
|
|
107
118
|
"dist"
|
|
108
|
-
]
|
|
119
|
+
],
|
|
120
|
+
"engines": {
|
|
121
|
+
"node": ">=20"
|
|
122
|
+
}
|
|
109
123
|
}
|