Skip to content

Commit 89582d3

Browse files
authored
feat: basic implementation for PostgresDriver (#20)
- Some tests fail currently. - Not all features have been implemented yet.
1 parent 558d598 commit 89582d3

41 files changed

Lines changed: 891 additions & 341 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/ci.yml‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@ on: [push, pull_request]
33
jobs:
44
build:
55
runs-on: ubuntu-latest
6+
services:
7+
postgres:
8+
image: postgres:11
9+
env:
10+
POSTGRES_USER: test
11+
POSTGRES_PASSWORD: test
12+
POSTGRES_DB: test
13+
ports:
14+
- 5432:5432
615
steps:
716
- uses: actions/checkout@master
817
- uses: denolib/setup-deno@master
@@ -11,4 +20,4 @@ jobs:
1120
- name: Run tests
1221
run: |
1322
cp ./ormconfig.gh-actions.json ./ormconfig.json
14-
deno run --allow-read --allow-write --allow-env --config ./tsconfig.json ./test.ts
23+
deno run --allow-read --allow-write --allow-env --allow-net --config ./tsconfig.json ./test.ts

‎dem.json‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,16 @@
88
"/fmt/colors.ts",
99
"/fs/mod.ts",
1010
"/node/module.ts",
11-
"/path/mod.ts"
11+
"/path/mod.ts",
12+
"/util/async.ts"
13+
]
14+
},
15+
{
16+
"protocol": "https",
17+
"path": "deno.land/x/postgres",
18+
"version": "v0.3.8",
19+
"files": [
20+
"/mod.ts"
1221
]
1322
},
1423
{

‎ormconfig.gh-actions.json‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,16 @@
55
"type": "sqlite",
66
"database": ":memory:",
77
"logging": false
8+
},
9+
{
10+
"skip": true,
11+
"name": "postgres",
12+
"type": "postgres",
13+
"host": "localhost",
14+
"port": 5432,
15+
"username": "test",
16+
"password": "test",
17+
"database": "test",
18+
"logging": false
819
}
920
]

‎src/connection/Connection.ts‎

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {RelationLoader} from "../query-builder/RelationLoader.ts";
3232
import {RelationIdLoader} from "../query-builder/RelationIdLoader.ts";
3333
import {EntitySchema} from "../index.ts";
3434
import {ObjectUtils} from "../util/ObjectUtils.ts";
35+
import {PromiseUtils} from "../util/PromiseUtils.ts";
3536
import {IsolationLevel} from "../driver/types/IsolationLevel.ts";
3637
import {QueryBuilderFactory} from "../query-builder/QueryBuilderFactory.ts";
3738

@@ -255,7 +256,19 @@ export class Connection {
255256
async dropDatabase(): Promise<void> {
256257
const queryRunner = this.createQueryRunner("master");
257258
try {
258-
await queryRunner.clearDatabase();
259+
if (
260+
false/*this.driver instanceof SqlServerDriver ||*/ // TODO(uki00a) uncomment this when SqlServerDriver is implemented.
261+
/* this.driver instanceof MysqlDriver ||*/ // TODO(uki00a) uncomment this when MysqlDriver is implemented.
262+
/*this.driver instanceof AuroraDataApiDriver*/) { // TODO(uki00a) uncomment this when AuroraDataApiDriver is implemented.
263+
const databases: string[] = this.driver.database ? [this.driver.database] : [];
264+
this.entityMetadatas.forEach(metadata => {
265+
if (metadata.database && databases.indexOf(metadata.database) === -1)
266+
databases.push(metadata.database);
267+
});
268+
await PromiseUtils.runInSequence(databases, database => queryRunner.clearDatabase(database));
269+
} else {
270+
await queryRunner.clearDatabase();
271+
}
259272
} finally {
260273
await queryRunner.release();
261274
}
@@ -514,13 +527,13 @@ export class Connection {
514527
protected getDatabaseName(): string {
515528
const options = this.options;
516529
switch (options.type) {
517-
// case "mysql" :
518-
// case "mariadb" :
519-
// case "postgres":
520-
// case "cockroachdb":
521-
// case "mssql":
522-
// case "oracle":
523-
// return (options.replication ? options.replication.master.database : options.database) as string;
530+
case "mysql" :
531+
case "mariadb" :
532+
case "postgres":
533+
// case "cockroachdb": // TODO(uki00a) uncomment this when CockroachDriver is implemented.
534+
// case "mssql": // TODO(uki00a) uncomment this when SqlServerDriver is implemented.
535+
// case "oracle": // TODO(uki00a) uncomment this when OracleDriver is implemented.
536+
return (options.replication ? options.replication.master.database : options.database) as string;
524537
default:
525538
return options.database as string;
526539
}

‎src/connection/ConnectionOptions.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {SqliteConnectionOptions} from "../driver/sqlite/SqliteConnectionOptions.ts";
22
import {MysqlConnectionOptions} from "../driver/mysql/MysqlConnectionOptions.ts";
3+
import {PostgresConnectionOptions} from "../driver/postgres/PostgresConnectionOptions.ts";
34

45

56
/**
@@ -9,4 +10,5 @@ import {MysqlConnectionOptions} from "../driver/mysql/MysqlConnectionOptions.ts"
910
*/
1011
export type ConnectionOptions =
1112
SqliteConnectionOptions|
12-
MysqlConnectionOptions;
13+
MysqlConnectionOptions|
14+
PostgresConnectionOptions;

‎src/driver/DriverFactory.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {MissingDriverError} from "../error/MissingDriverError.ts";
22
import {SqliteDriver} from "./sqlite/SqliteDriver.ts";
33
import {Driver} from "./Driver.ts";
44
import {Connection} from "../connection/Connection.ts";
5+
import {PostgresDriver} from "./postgres/PostgresDriver.ts";
56

67
/**
78
* Helps to create drivers.
@@ -14,6 +15,8 @@ export class DriverFactory {
1415
create(connection: Connection): Driver {
1516
const {type} = connection.options;
1617
switch (type) {
18+
case "postgres":
19+
return new PostgresDriver(connection);
1720
case "sqlite":
1821
return new SqliteDriver(connection);
1922
default:

‎src/driver/postgres/PostgresConnectionCredentialsOptions.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TlsOptions } from "tls";
1+
//import { TlsOptions } from "tls";
22

33
/**
44
* Postgres specific connection credential options.
@@ -38,6 +38,6 @@ export interface PostgresConnectionCredentialsOptions {
3838
/**
3939
* Object with ssl parameters
4040
*/
41-
readonly ssl?: boolean | TlsOptions;
41+
readonly ssl?: boolean | Deno.ListenTLSOptions;
4242

4343
}

0 commit comments

Comments
 (0)