Skip to content

Commit

Permalink
[SOA-589] feat(app): Add Session Pool Options to the Spanner connecti…
Browse files Browse the repository at this point in the history
…on (#11)

* Add Session Pool Options to the Spanner connection

* One formatting too much
  • Loading branch information
MuFa117 committed Aug 24, 2023
1 parent 5f88552 commit b9aca7e
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 8 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@streamyard/typeorm",
"private": true,
"version": "0.3.16-2",
"version": "0.3.16-3",
"description": "Data-Mapper ORM for TypeScript, ES7, ES6, ES5. Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, MongoDB, Spanner databases.",
"license": "MIT",
"readmeFilename": "README.md",
Expand Down
5 changes: 4 additions & 1 deletion src/driver/spanner/SpannerConnectionOptions.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { BaseConnectionOptions } from "../../connection/BaseConnectionOptions"
import { SpannerConnectionCredentialsOptions } from "./SpannerConnectionCredentialsOptions"
import { SpannerSessionPoolOptions } from "./SpannerSessionPoolOptions"

/**
* Spanner specific connection options.
*/
export interface SpannerConnectionOptions
extends BaseConnectionOptions,
SpannerConnectionCredentialsOptions {
SpannerConnectionCredentialsOptions {
/**
* Database type.
*/
Expand Down Expand Up @@ -146,4 +147,6 @@ export interface SpannerConnectionOptions
}

readonly poolSize?: never

readonly sessionPool?: SpannerSessionPoolOptions
}
8 changes: 4 additions & 4 deletions src/driver/spanner/SpannerDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export class SpannerDriver implements Driver {
*/
async connect(): Promise<void> {
this.instance = this.spanner.instance(this.options.instanceId)
this.instanceDatabase = this.instance.database(this.options.databaseId)
this.instanceDatabase = this.instance.database(this.options.databaseId, this.options.sessionPool ?? {})
}

/**
Expand Down Expand Up @@ -422,9 +422,9 @@ export class SpannerDriver implements Driver {
if (value === null || value === undefined)
return columnMetadata.transformer
? ApplyValueTransformers.transformFrom(
columnMetadata.transformer,
value,
)
columnMetadata.transformer,
value,
)
: value

if (columnMetadata.type === Boolean || columnMetadata.type === "bool") {
Expand Down
38 changes: 38 additions & 0 deletions src/driver/spanner/SpannerSessionPoolOptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Spanner specific SessionPool options
* more: https://github.com/ko3a4ok/nodejs-spanner/blob/aa8e8becf74d41d0de68253c17ebab188b5c7620/src/session-pool.ts#L149
*/
export interface SpannerSessionPoolOptions {
acquireTimeout?: number;
concurrency?: number;
fail?: boolean;
idlesAfter?: number;
keepAlive?: number;
labels?: { [label: string]: string };
max?: number;
maxIdle?: number;
min?: number;
/**
* @deprecated. Starting from v6.5.0 the same session can be reused for
* different types of transactions.
*/
writes?: number;
incStep?: number;
databaseRole?: string | null;
}

/* Defaults:
const DEFAULTS: SessionPoolOptions = {
acquireTimeout: Infinity,
concurrency: Infinity,
fail: false,
idlesAfter: 10,
keepAlive: 30,
labels: {},
max: 100,
maxIdle: 1,
min: 25,
incStep: 25,
databaseRole: null,
};
*/

0 comments on commit b9aca7e

Please sign in to comment.