Skip to content

Commit

Permalink
Merge pull request #3190 from saboya/sqlite-on-conflict
Browse files Browse the repository at this point in the history
Add flag to enable ON CONFLICT support for Sqlite.
  • Loading branch information
pleerock committed Dec 6, 2018
2 parents 578d500 + a6c1d41 commit efb6353
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ before_script:
- sudo service postgresql stop
- docker-compose up -d
- cp ormconfig.travis.json ormconfig.json
- npm install sqlite3 --build-from-source

script:
- npm test
Expand Down
3 changes: 2 additions & 1 deletion src/query-builder/InsertQueryBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {SqljsDriver} from "../driver/sqljs/SqljsDriver";
import {BroadcasterResult} from "../subscriber/BroadcasterResult";
import {EntitySchema} from "../";
import {OracleDriver} from "../driver/oracle/OracleDriver";
import {SqliteDriver} from "../driver/sqlite/SqliteDriver";

/**
* Allows to build complex sql queries in a fashion way and execute those queries.
Expand Down Expand Up @@ -299,7 +300,7 @@ export class InsertQueryBuilder<Entity> extends QueryBuilder<Entity> {
query += ` DEFAULT VALUES`;
}
}
if (this.connection.driver instanceof PostgresDriver) {
if (this.connection.driver instanceof PostgresDriver || (this.connection.driver instanceof SqliteDriver)) {
query += `${this.expressionMap.onIgnore ? " ON CONFLICT DO NOTHING " : ""}`;
query += `${this.expressionMap.onConflict ? " ON CONFLICT " + this.expressionMap.onConflict : ""}`;
if (this.expressionMap.onUpdate) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import {Connection} from "../../../../src/connection/Connection";
import {Post} from "./entity/Post";

describe("query builder > insertion > on conflict", () => {

let connections: Connection[];
before(async () => connections = await createTestingConnections({
entities: [__dirname + "/entity/*{.js,.ts}"],
enabledDrivers: ["postgres"] // since on conflict statement is only supported in postgres
enabledDrivers: ["postgres", "sqlite"] // since on conflict statement is only supported in postgres and sqlite >= 3.24.0
}));
beforeEach(() => reloadTestingDatabases(connections));
after(() => closeTestingConnections(connections));
Expand Down

0 comments on commit efb6353

Please sign in to comment.