Skip to content

Commit

Permalink
feat!: upgrade to aws-sdk-v3 (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
Newbie012 authored Mar 1, 2023
1 parent f09b3b7 commit 5d2417c
Show file tree
Hide file tree
Showing 5 changed files with 746 additions and 125 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@
"build:cjs": "tsc -p tsconfig-cjs.json"
},
"devDependencies": {
"@aws-sdk/client-rds-data": "^3.218.0",
"@changesets/changelog-github": "^0.4.5",
"@changesets/cli": "^2.23.2",
"@tsconfig/node14": "^1.0.1",
"@types/node": "^16.11.0",
"aws-sdk": "^2.1008.0",
"kysely": "^0.19.3",
"perf_hooks": "^0.0.1",
"vitest": "^0.18.1"
},
"peerDependencies": {
"aws-sdk": "2.x",
"@aws-sdk/client-rds-data": "3.x",
"kysely": "0.x"
},
"files": [
Expand Down
22 changes: 8 additions & 14 deletions src/data-api-driver.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { DatabaseConnection, QueryResult } from "kysely";
import { Driver } from "kysely";
import { CompiledQuery } from "kysely";
import RDSDataService, { SqlParametersList } from "aws-sdk/clients/rdsdataservice.js";
import { RDSData, SqlParameter } from "@aws-sdk/client-rds-data";
import { CompiledQuery, DatabaseConnection, Driver, QueryResult } from "kysely";

export type DataApiDriverConfig = {
client: RDSDataService;
client: RDSData;
secretArn: string;
resourceArn: string;
database: string;
Expand Down Expand Up @@ -60,8 +58,7 @@ class DataApiConnection implements DatabaseConnection {
secretArn: this.#config.secretArn,
resourceArn: this.#config.resourceArn,
database: this.#config.database,
})
.promise();
});
this.#transactionId = r.transactionId;
}

Expand All @@ -73,8 +70,7 @@ class DataApiConnection implements DatabaseConnection {
secretArn: this.#config.secretArn,
resourceArn: this.#config.resourceArn,
transactionId: this.#transactionId,
})
.promise();
});
}

public async rollbackTransaction() {
Expand All @@ -85,8 +81,7 @@ class DataApiConnection implements DatabaseConnection {
secretArn: this.#config.secretArn,
resourceArn: this.#config.resourceArn,
transactionId: this.#transactionId,
})
.promise();
});
}

async executeQuery<O>(compiledQuery: CompiledQuery): Promise<QueryResult<O>> {
Expand All @@ -96,11 +91,10 @@ class DataApiConnection implements DatabaseConnection {
secretArn: this.#config.secretArn,
resourceArn: this.#config.resourceArn,
sql: compiledQuery.sql,
parameters: compiledQuery.parameters as SqlParametersList,
parameters: compiledQuery.parameters as SqlParameter[],
database: this.#config.database,
includeResultMetadata: true,
})
.promise();
});
if (!r.columnMetadata) {
return {
numUpdatedOrDeletedRows: BigInt(r.numberOfRecordsUpdated || 0),
Expand Down
2 changes: 1 addition & 1 deletion src/data-api-query-compiler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SqlParameter } from "aws-sdk/clients/rdsdataservice";
import { SqlParameter } from "@aws-sdk/client-rds-data";
import { MysqlQueryCompiler, PostgresQueryCompiler } from "kysely";

export class PostgresDataApiQueryCompiler extends PostgresQueryCompiler {
Expand Down
14 changes: 5 additions & 9 deletions test/harness.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import RDSDataService from "aws-sdk/clients/rdsdataservice";
import { RDSData } from "@aws-sdk/client-rds-data";
import { ColumnType, Generated, Kysely } from "kysely";
import { DataApiDialect } from "../src";
import { DataApiDriverConfig } from "../src/data-api-driver";
Expand All @@ -7,15 +7,14 @@ import path from "path";
const TEST_DATABASE = "scratch";

const opts: DataApiDriverConfig = {
client: new RDSDataService(),
client: new RDSData({}),
database: TEST_DATABASE,
secretArn: process.env.RDS_SECRET,
resourceArn: process.env.RDS_ARN,
};
const dialect = new DataApiDialect({
mode: "postgres",
driver: opts,
mode: "postgres",
});

export interface Person {
Expand Down Expand Up @@ -54,26 +53,23 @@ export async function migrate() {
database: "postgres",
secretArn: opts.secretArn,
resourceArn: opts.resourceArn,
})
.promise();
});

await opts.client
.executeStatement({
sql: `DROP DATABASE IF EXISTS ${TEST_DATABASE}`,
database: "postgres",
secretArn: opts.secretArn,
resourceArn: opts.resourceArn,
})
.promise();
});

await opts.client
.executeStatement({
sql: `CREATE DATABASE ${TEST_DATABASE}`,
database: "postgres",
secretArn: opts.secretArn,
resourceArn: opts.resourceArn,
})
.promise();
});

await db.migration.migrateToLatest(path.resolve("./test/migrations"));
}
Expand Down
Loading

0 comments on commit 5d2417c

Please sign in to comment.