Skip to content

Commit

Permalink
Merge pull request typeorm#1340 from daniel-lang/next
Browse files Browse the repository at this point in the history
Merge sql.js specific changes from master into next
  • Loading branch information
pleerock authored Dec 13, 2017
2 parents cc23942 + 0d5d9d2 commit 2fd585f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 17 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,12 @@ Use `findOne(id)` method instead now.
* `@DiscriminatorColumn` decorator has been removed, use `@TableInheritance` options instead now
* `skipSync` in entity options has been renamed to `synchronize`. Now if it set to false schema synchronization for the entity will be disabled.
By default its true.
* `sqljs` driver now enforces FK integrity by default (same behavior as `sqlite`).
* now array initializations for relations are forbidden and ORM throws an error if there are entities with initialized relation arrays.

## 0.1.10

* `sqljs` driver now enforces FK integrity by default (same behavior as `sqlite`)

## 0.1.9

* fixed bug with sqlite and mysql schema synchronization when uuid column is used ([#1332](https://github.com/typeorm/typeorm/issues/1332))
Expand Down
13 changes: 10 additions & 3 deletions src/driver/sqljs/SqljsDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,16 @@ export class SqljsDriver extends AbstractSqliteDriver {
this.databaseConnection = new this.sqlite.Database();
}

const queryRunner = this.createQueryRunner("master");
await queryRunner.query(`PRAGMA foreign_keys = ON;`);
return this.databaseConnection;
// Enable foreign keys for database
return new Promise<any>((ok, fail) => {
try {
this.databaseConnection.exec(`PRAGMA foreign_keys = ON;`);
ok(this.databaseConnection);
}
catch (e) {
fail(e);
}
});
}

/**
Expand Down
32 changes: 20 additions & 12 deletions test/functional/sqljs/auto-save.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import "reflect-metadata";
import {expect} from "chai";
import {createConnection} from "../../../src/index";
import {Post} from "./entity/Post";
import {createTestingConnections} from "../../utils/test-utils";

describe("sqljs driver > autosave", () => {
it("should call autoSaveCallback on insert, update and delete", async () => {
Expand All @@ -10,14 +10,18 @@ describe("sqljs driver > autosave", () => {
saves++;
};

let connection = await createConnection({
type: "sqljs",
let connections = await createTestingConnections({
enabledDrivers: ["sqljs"],
entities: [Post],
synchronize: true,
autoSaveCallback: callback,
autoSave: true
schemaCreate: true,
driverSpecific: {
autoSaveCallback: callback,
autoSave: true
}
});

const connection = connections[0];

let posts = [
{
title: "second post"
Expand Down Expand Up @@ -56,14 +60,18 @@ describe("sqljs driver > autosave", () => {
const callback = (database: Uint8Array) => {
saves++;
};

let connection = await createConnection({
type: "sqljs",
let connections = await createTestingConnections({
enabledDrivers: ["sqljs"],
entities: [Post],
synchronize: true,
autoSaveCallback: callback,
autoSave: false
schemaCreate: true,
driverSpecific: {
autoSaveCallback: callback,
autoSave: false
}
});

let connection = connections[0];

const repository = connection.getRepository(Post);
let post = new Post();
Expand Down
9 changes: 8 additions & 1 deletion test/utils/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ export interface TestingOptions {

};

/**
* Options that may be specific to a driver.
* They are passed down to the enabled drivers.
*/
driverSpecific?: Object;
}

/**
Expand Down Expand Up @@ -184,14 +189,16 @@ export function setupTestingConnections(options?: TestingOptions): ConnectionOpt
return true;
})
.map(connectionOptions => {
const newOptions: any = Object.assign({}, connectionOptions as ConnectionOptions, {
let newOptions: any = Object.assign({}, connectionOptions as ConnectionOptions, {
name: options && options.name ? options.name : connectionOptions.name,
entities: options && options.entities ? options.entities : [],
subscribers: options && options.subscribers ? options.subscribers : [],
entitySchemas: options && options.entitySchemas ? options.entitySchemas : [],
dropSchema: options && (options.entities || options.entitySchemas) ? options.dropSchema : false,
cache: options ? options.cache : undefined,
});
if (options && options.driverSpecific)
newOptions = Object.assign({}, options.driverSpecific, newOptions);
if (options && options.schemaCreate)
newOptions.synchronize = options.schemaCreate;
if (options && options.schema)
Expand Down

0 comments on commit 2fd585f

Please sign in to comment.