Skip to content

Commit

Permalink
fix: make compilation pass with deno (#2)
Browse files Browse the repository at this point in the history
* chore: initial setup
* fix: make compilation pass with deno
  • Loading branch information
uki00a authored Jan 19, 2020
1 parent 00c9f4b commit 5cbe0f6
Show file tree
Hide file tree
Showing 290 changed files with 2,183 additions and 2,698 deletions.
29 changes: 29 additions & 0 deletions dem.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"modules": [
{
"protocol": "https",
"path": "deno.land/std",
"version": "v0.30.0",
"files": [
"/fmt/colors.ts",
"/fs/mod.ts",
"/node/module.ts",
"/path/mod.ts"
]
},
{
"protocol": "https",
"path": "deno.land/x/sha256",
"version": "v1.0.0",
"files": [
"/mod.ts"
]
},
{
"protocol": "https",
"path": "deno.land/x/sqlite",
"version": "defb9c019165f23d072451b7c56176be440161e7",
"files": []
}
]
}
128 changes: 128 additions & 0 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@
"ts-node": "^8.0.2",
"tslint": "^5.13.1",
"typeorm-aurora-data-api-driver": "^1.1.1",
"typescript": "^3.3.3333"
"typescript": "^3.3.3333",
"typescript-deno-plugin": "^1.2.7"
},
"dependencies": {
"app-root-path": "^3.0.0",
Expand Down
2 changes: 2 additions & 0 deletions src/Reflect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// TODO(uki00a) dem
import "https://deno.land/x/dso@0.6.1/src/Reflect.ts";
46 changes: 11 additions & 35 deletions src/cache/DbQueryResultCache.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import {ObjectLiteral} from "../common/ObjectLiteral";
import {Connection} from "../connection/Connection";
import {OracleDriver} from "../driver/oracle/OracleDriver";
import {PostgresConnectionOptions} from "../driver/postgres/PostgresConnectionOptions";
import {MssqlParameter} from "../driver/sqlserver/MssqlParameter";
import {SqlServerConnectionOptions} from "../driver/sqlserver/SqlServerConnectionOptions";
import {SqlServerDriver} from "../driver/sqlserver/SqlServerDriver";
import {QueryRunner} from "../query-runner/QueryRunner";
import {Table} from "../schema-builder/table/Table";
import {QueryResultCache} from "./QueryResultCache";
import {QueryResultCacheOptions} from "./QueryResultCacheOptions";
import {ObjectLiteral} from "../common/ObjectLiteral.ts";
import {Connection} from "../connection/Connection.ts";
import {QueryRunner} from "../query-runner/QueryRunner.ts";
import {Table} from "../schema-builder/table/Table.ts";
import {QueryResultCache} from "./QueryResultCache.ts";
import {QueryResultCacheOptions} from "./QueryResultCacheOptions.ts";

/**
* Caches query result into current database, into separate table called "query-result-cache".
Expand All @@ -27,11 +22,11 @@ export class DbQueryResultCache implements QueryResultCache {

constructor(protected connection: Connection) {

const options = <SqlServerConnectionOptions|PostgresConnectionOptions>this.connection.driver.options;
const options = this.connection.driver.options;
const cacheOptions = typeof this.connection.options.cache === "object" ? this.connection.options.cache : {};
const cacheTableName = cacheOptions.tableName || "query-result-cache";

this.queryResultCacheTable = this.connection.driver.buildTableName(cacheTableName, options.schema, options.database);
this.queryResultCacheTable = this.connection.driver.buildTableName(cacheTableName);
}

// -------------------------------------------------------------------------
Expand Down Expand Up @@ -120,19 +115,14 @@ export class DbQueryResultCache implements QueryResultCache {
if (options.identifier) {
return qb
.where(`${qb.escape("cache")}.${qb.escape("identifier")} = :identifier`)
.setParameters({ identifier: this.connection.driver instanceof SqlServerDriver ? new MssqlParameter(options.identifier, "nvarchar") : options.identifier })
.setParameters({ identifier: options.identifier })
.getRawOne();

} else if (options.query) {
if (this.connection.driver instanceof OracleDriver) {
return qb
.where(`dbms_lob.compare(${qb.escape("cache")}.${qb.escape("query")}, :query) = 0`, { query: options.query })
.getRawOne();
}

return qb
.where(`${qb.escape("cache")}.${qb.escape("query")} = :query`)
.setParameters({ query: this.connection.driver instanceof SqlServerDriver ? new MssqlParameter(options.query, "nvarchar") : options.query })
.setParameters({ query: options.query })
.getRawOne();
}

Expand All @@ -154,15 +144,6 @@ export class DbQueryResultCache implements QueryResultCache {
queryRunner = this.getQueryRunner(queryRunner);

let insertedValues: ObjectLiteral = options;
if (this.connection.driver instanceof SqlServerDriver) { // todo: bad abstraction, re-implement this part, probably better if we create an entity metadata for cache table
insertedValues = {
identifier: new MssqlParameter(options.identifier, "nvarchar"),
time: new MssqlParameter(options.time, "bigint"),
duration: new MssqlParameter(options.duration, "int"),
query: new MssqlParameter(options.query, "nvarchar"),
result: new MssqlParameter(options.result, "nvarchar"),
};
}

if (savedCache && savedCache.identifier) { // if exist then update
const qb = queryRunner.manager
Expand All @@ -179,12 +160,7 @@ export class DbQueryResultCache implements QueryResultCache {
.update(this.queryResultCacheTable)
.set(insertedValues);

if (this.connection.driver instanceof OracleDriver) {
qb.where(`dbms_lob.compare("query", :condition) = 0`, { condition: insertedValues.query });

} else {
qb.where(`${qb.escape("query")} = :condition`, { condition: insertedValues.query });
}
qb.where(`${qb.escape("query")} = :condition`, { condition: insertedValues.query });

await qb.execute();

Expand Down
6 changes: 3 additions & 3 deletions src/cache/QueryResultCache.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {QueryResultCacheOptions} from "./QueryResultCacheOptions";
import {QueryRunner} from "../query-runner/QueryRunner";
import {QueryResultCacheOptions} from "./QueryResultCacheOptions.ts";
import {QueryRunner} from "../query-runner/QueryRunner.ts";

/**
* Implementations of this interface provide different strategies to cache query builder results.
Expand Down Expand Up @@ -46,4 +46,4 @@ export interface QueryResultCache {
*/
remove(identifiers: string[], queryRunner?: QueryRunner): Promise<void>;

}
}
8 changes: 4 additions & 4 deletions src/cache/QueryResultCacheFactory.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {RedisQueryResultCache} from "./RedisQueryResultCache";
import {DbQueryResultCache} from "./DbQueryResultCache";
import {QueryResultCache} from "./QueryResultCache";
import {Connection} from "../connection/Connection";
import {RedisQueryResultCache} from "./RedisQueryResultCache.ts";
import {DbQueryResultCache} from "./DbQueryResultCache.ts";
import {QueryResultCache} from "./QueryResultCache.ts";
import {Connection} from "../connection/Connection.ts";

/**
* Caches query result into Redis database.
Expand Down
10 changes: 5 additions & 5 deletions src/cache/RedisQueryResultCache.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {QueryResultCache} from "./QueryResultCache";
import {QueryResultCacheOptions} from "./QueryResultCacheOptions";
import {PlatformTools} from "../platform/PlatformTools";
import {Connection} from "../connection/Connection";
import {QueryRunner} from "../query-runner/QueryRunner";
import {QueryResultCache} from "./QueryResultCache.ts";
import {QueryResultCacheOptions} from "./QueryResultCacheOptions.ts";
import {PlatformTools} from "../platform/PlatformTools.ts";
import {Connection} from "../connection/Connection.ts";
import {QueryRunner} from "../query-runner/QueryRunner.ts";

/**
* Caches query result into Redis database.
Expand Down
28 changes: 14 additions & 14 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
#!/usr/bin/env node
import "reflect-metadata";
import * as yargs from "yargs";
import {SchemaSyncCommand} from "./commands/SchemaSyncCommand";
import {SchemaDropCommand} from "./commands/SchemaDropCommand";
import {QueryCommand} from "./commands/QueryCommand";
import {EntityCreateCommand} from "./commands/EntityCreateCommand";
import {MigrationCreateCommand} from "./commands/MigrationCreateCommand";
import {MigrationRunCommand} from "./commands/MigrationRunCommand";
import {MigrationRevertCommand} from "./commands/MigrationRevertCommand";
import {MigrationShowCommand} from "./commands/MigrationShowCommand";
import {SubscriberCreateCommand} from "./commands/SubscriberCreateCommand";
import {SchemaLogCommand} from "./commands/SchemaLogCommand";
import {MigrationGenerateCommand} from "./commands/MigrationGenerateCommand";
import {VersionCommand} from "./commands/VersionCommand";
import {InitCommand} from "./commands/InitCommand";
import {CacheClearCommand} from "./commands/CacheClearCommand";
import {SchemaSyncCommand} from "./commands/SchemaSyncCommand.ts";
import {SchemaDropCommand} from "./commands/SchemaDropCommand.ts";
import {QueryCommand} from "./commands/QueryCommand.ts";
import {EntityCreateCommand} from "./commands/EntityCreateCommand.ts";
import {MigrationCreateCommand} from "./commands/MigrationCreateCommand.ts";
import {MigrationRunCommand} from "./commands/MigrationRunCommand.ts";
import {MigrationRevertCommand} from "./commands/MigrationRevertCommand.ts";
import {MigrationShowCommand} from "./commands/MigrationShowCommand.ts";
import {SubscriberCreateCommand} from "./commands/SubscriberCreateCommand.ts";
import {SchemaLogCommand} from "./commands/SchemaLogCommand.ts";
import {MigrationGenerateCommand} from "./commands/MigrationGenerateCommand.ts";
import {VersionCommand} from "./commands/VersionCommand.ts";
import {InitCommand} from "./commands/InitCommand.ts";
import {CacheClearCommand} from "./commands/CacheClearCommand.ts";

yargs
.usage("Usage: $0 <command> [options]")
Expand Down
6 changes: 3 additions & 3 deletions src/commands/MigrationShowCommand.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {createConnection} from "../index";
import {ConnectionOptionsReader} from "../connection/ConnectionOptionsReader";
import {Connection} from "../connection/Connection";
import {createConnection} from "../index.ts";
import {ConnectionOptionsReader} from "../connection/ConnectionOptionsReader.ts";
import {Connection} from "../connection/Connection.ts";
import * as process from "process";
import * as yargs from "yargs";
const chalk = require("chalk");
Expand Down
Loading

0 comments on commit 5cbe0f6

Please sign in to comment.