diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000000..c4ba021d0b --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,204 @@ +# https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs +# https://docs.github.com/en/actions/use-cases-and-examples/building-and-testing/building-and-testing-nodejs +# https://docs.github.com/en/actions/use-cases-and-examples/using-containerized-services/creating-postgresql-service-containers + +name: test + +on: + push: + branches: [ "**" ] + pull_request: + branches: [ "master" ] + +jobs: + cockroachdb: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + node-version: [18.x] #["node:16", "node:18", "node:20", "node:22"] + # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ + + steps: + - uses: actions/setup-node@v4 + with: + node-version: ${{matrix.node-version}} + - uses: actions/checkout@v4 + - run: docker compose -f .github/workflows/test/cockroachdb.docker-compose up -d + - run: npm i + - run: cp .github/workflows/test/cockroachdb.ormconfig.json ormconfig.json + - run: npm test + + + mongodb: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + node-container: ["node:18"] #["node:16", "node:18", "node:20", "node:22"] + # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ + + container: ${{ matrix.node-container }} + services: + mongodb: + image: mongo:5.0.12 + + steps: + - uses: actions/checkout@v4 + - run: npm i + - run: cp .github/workflows/test/mongodb.ormconfig.json ormconfig.json + - run: npm test + + + mssql: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + node-container: ["node:18"] #["node:16", "node:18", "node:20", "node:22"] + # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ + + container: ${{ matrix.node-container }} + services: + mssql: + image: "mcr.microsoft.com/mssql/server:2022-latest" + env: + SA_PASSWORD: "Admin12345" + ACCEPT_EULA: "Y" + + steps: + - uses: actions/checkout@v4 + - run: npm i + - run: cp .github/workflows/test/mssql.ormconfig.json ormconfig.json + - run: npm test + + + mysql_mariadb: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + node-container: ["node:18"] #["node:16", "node:18", "node:20", "node:22"] + # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ + + container: ${{ matrix.node-container }} + services: + mysql: + image: mysql:5.7.37 + env: + MYSQL_ROOT_PASSWORD: "admin" + MYSQL_USER: "test" + MYSQL_PASSWORD: "test" + MYSQL_DATABASE: "test" + mariadb: + image: mariadb:10.10.3 + env: + MYSQL_ROOT_PASSWORD: "admin" + MYSQL_USER: "test" + MYSQL_PASSWORD: "test" + MYSQL_DATABASE: "test" + + steps: + - uses: actions/checkout@v4 + - run: npm i + - run: cp .github/workflows/test/mysql-mariadb.ormconfig.json ormconfig.json + - run: npm test + + + oracle: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + node-version: [18.x] #["node:16", "node:18", "node:20", "node:22"] + # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ + + steps: + - uses: actions/setup-node@v4 + with: + node-version: ${{matrix.node-version}} + - uses: actions/checkout@v4 + - run: docker compose -f .github/workflows/test/oracle.docker-compose up -d + - run: npm i + - run: cp .github/workflows/test/oracle.ormconfig.json ormconfig.json + - run: npm test + + + better-sqlite3: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + node-container: ["node:18"] #["node:16", "node:18", "node:20", "node:22"] + # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ + + container: ${{ matrix.node-container }} + + steps: + - uses: actions/checkout@v4 + - run: npm i + - run: cp .github/workflows/test/better-sqlite3.ormconfig.json ormconfig.json + - run: npm test + + + sqlite: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + node-container: ["node:18"] #["node:16", "node:18", "node:20", "node:22"] + # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ + + container: ${{ matrix.node-container }} + + steps: + - uses: actions/checkout@v4 + - run: npm i + - run: cp .github/workflows/test/sqlite.ormconfig.json ormconfig.json + - run: npm test + + + sqljs: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + node-container: ["node:18"] #["node:16", "node:18", "node:20", "node:22"] + # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ + + container: ${{ matrix.node-container }} + + steps: + - uses: actions/checkout@v4 + - run: npm i + - run: cp .github/workflows/test/sqljs.ormconfig.json ormconfig.json + - run: npm test + + + posgres: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + node-container: ["node:18"] #["node:16", "node:18", "node:20", "node:22"] + # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ + + container: ${{ matrix.node-container }} + services: + postgres: + image: postgis/postgis:14-3.3 + env: + POSTGRES_USERNAME: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: postgres + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + + steps: + - uses: actions/checkout@v4 + - run: npm i + - run: cp .github/workflows/test/postgres.ormconfig.json ormconfig.json + - run: npm test diff --git a/.github/workflows/test/better-sqlite3.ormconfig.json b/.github/workflows/test/better-sqlite3.ormconfig.json new file mode 100644 index 0000000000..63836497d5 --- /dev/null +++ b/.github/workflows/test/better-sqlite3.ormconfig.json @@ -0,0 +1,21 @@ +[ + { + "skip": false, + "name": "better-sqlite3", + "type": "better-sqlite3", + "database": "temp/better-sqlite3db.db", + "logging": false + }, + + { + "skip": true, + "name": "postgres", + "type": "postgres", + "host": "postgres", + "port": 5432, + "username": "postgres", + "password": "postgres", + "database": "postgres", + "logging": false + } +] diff --git a/.github/workflows/test/cockroachdb.docker-compose b/.github/workflows/test/cockroachdb.docker-compose new file mode 100644 index 0000000000..448ca832c3 --- /dev/null +++ b/.github/workflows/test/cockroachdb.docker-compose @@ -0,0 +1,8 @@ +version: "3" +services: + cockroachdb: + image: "cockroachdb/cockroach:v23.1.9" + container_name: "typeorm-cockroachdb" + command: start-single-node --insecure --cache=0.75 --store=type=mem,size=0.75 + ports: + - "26257:26257" diff --git a/.github/workflows/test/cockroachdb.ormconfig.json b/.github/workflows/test/cockroachdb.ormconfig.json new file mode 100644 index 0000000000..e9501327a6 --- /dev/null +++ b/.github/workflows/test/cockroachdb.ormconfig.json @@ -0,0 +1,24 @@ +[ + { + "skip": false, + "name": "cockroachdb", + "type": "cockroachdb", + "host": "localhost", + "port": 26257, + "username": "root", + "password": "", + "database": "defaultdb" + }, + + { + "skip": true, + "name": "postgres", + "type": "postgres", + "host": "postgres", + "port": 5432, + "username": "postgres", + "password": "postgres", + "database": "postgres", + "logging": false + } +] diff --git a/.github/workflows/test/mongodb.ormconfig.json b/.github/workflows/test/mongodb.ormconfig.json new file mode 100644 index 0000000000..c03c017646 --- /dev/null +++ b/.github/workflows/test/mongodb.ormconfig.json @@ -0,0 +1,26 @@ +[ + { + "skip": false, + "disabledIfNotEnabledImplicitly": true, + "name": "mongodb", + "type": "mongodb", + "host": "mongodb", + "port": 27017, + "database": "test", + "logging": false, + "useNewUrlParser": true, + "useUnifiedTopology": true + }, + + { + "skip": true, + "name": "postgres", + "type": "postgres", + "host": "postgres", + "port": 5432, + "username": "postgres", + "password": "postgres", + "database": "postgres", + "logging": false + } +] diff --git a/.github/workflows/test/mssql.ormconfig.json b/.github/workflows/test/mssql.ormconfig.json new file mode 100644 index 0000000000..570bee1276 --- /dev/null +++ b/.github/workflows/test/mssql.ormconfig.json @@ -0,0 +1,28 @@ +[ + { + "skip": false, + "name": "mssql", + "type": "mssql", + "host": "mssql", + "port": 1433, + "username": "sa", + "password": "Admin12345", + "database": "tempdb", + "logging": false, + "extra": { + "trustServerCertificate": true + } + }, + + { + "skip": true, + "name": "postgres", + "type": "postgres", + "host": "postgres", + "port": 5432, + "username": "postgres", + "password": "postgres", + "database": "postgres", + "logging": false + } +] diff --git a/.github/workflows/test/mysql-mariadb.ormconfig.json b/.github/workflows/test/mysql-mariadb.ormconfig.json new file mode 100644 index 0000000000..9b06509d52 --- /dev/null +++ b/.github/workflows/test/mysql-mariadb.ormconfig.json @@ -0,0 +1,36 @@ +[ + { + "skip": false, + "name": "mysql", + "type": "mysql", + "host": "mysql", + "port": 3306, + "username": "root", + "password": "admin", + "database": "test", + "logging": false + }, + { + "skip": false, + "name": "mariadb", + "type": "mariadb", + "host": "mariadb", + "port": 3306, + "username": "root", + "password": "admin", + "database": "test", + "logging": false + }, + + { + "skip": true, + "name": "postgres", + "type": "postgres", + "host": "postgres", + "port": 5432, + "username": "postgres", + "password": "postgres", + "database": "postgres", + "logging": false + } +] diff --git a/.github/workflows/test/oracle.docker-compose b/.github/workflows/test/oracle.docker-compose new file mode 100644 index 0000000000..2f79eab314 --- /dev/null +++ b/.github/workflows/test/oracle.docker-compose @@ -0,0 +1,13 @@ +version: "3" +services: + oracle: + build: + context: ../../../docker/oracle + container_name: "typeorm-oracle" + ports: + - "1521:1521" + #volumes: + # - oracle-data:/opt/oracle/oradata + healthcheck: + test: [ "CMD", "/opt/oracle/checkDBStatus.sh" ] + interval: 2s \ No newline at end of file diff --git a/.github/workflows/test/oracle.ormconfig.json b/.github/workflows/test/oracle.ormconfig.json new file mode 100644 index 0000000000..9bf120d624 --- /dev/null +++ b/.github/workflows/test/oracle.ormconfig.json @@ -0,0 +1,28 @@ +[ + { + "skip": false, + "name": "oracle", + "type": "oracle", + "host": "localhost", + "port": 1521, + "serviceName": "XEPDB1", + "username": "typeorm", + "password": "oracle", + "logging": false, + "extra": { + "connectString": "localhost:1521/XEPDB1" + } + }, + + { + "skip": true, + "name": "postgres", + "type": "postgres", + "host": "postgres", + "port": 5432, + "username": "postgres", + "password": "postgres", + "database": "postgres", + "logging": false + } +] diff --git a/.github/workflows/test/postgres.ormconfig.json b/.github/workflows/test/postgres.ormconfig.json new file mode 100644 index 0000000000..dd20cd4c08 --- /dev/null +++ b/.github/workflows/test/postgres.ormconfig.json @@ -0,0 +1,13 @@ +[ + { + "skip": false, + "name": "postgres", + "type": "postgres", + "host": "postgres", + "port": 5432, + "username": "postgres", + "password": "postgres", + "database": "postgres", + "logging": false + } +] diff --git a/.github/workflows/test/sqlite.ormconfig.json b/.github/workflows/test/sqlite.ormconfig.json new file mode 100644 index 0000000000..55a30706a8 --- /dev/null +++ b/.github/workflows/test/sqlite.ormconfig.json @@ -0,0 +1,22 @@ +[ + { + "skip": false, + "name": "sqlite", + "type": "sqlite", + "database": "./temp/sqlitedb-1.db", + "logging": false, + "relationLoadStrategy": "join" + }, + + { + "skip": true, + "name": "postgres", + "type": "postgres", + "host": "postgres", + "port": 5432, + "username": "postgres", + "password": "postgres", + "database": "postgres", + "logging": false + } +] diff --git a/.github/workflows/test/sqljs.ormconfig.json b/.github/workflows/test/sqljs.ormconfig.json new file mode 100644 index 0000000000..897ada4114 --- /dev/null +++ b/.github/workflows/test/sqljs.ormconfig.json @@ -0,0 +1,20 @@ +[ + { + "skip": false, + "name": "sqljs", + "type": "sqljs", + "logging": false + }, + + { + "skip": true, + "name": "postgres", + "type": "postgres", + "host": "postgres", + "port": 5432, + "username": "postgres", + "password": "postgres", + "database": "postgres", + "logging": false + } +] diff --git a/src/driver/better-sqlite3/BetterSqlite3QueryRunner.ts b/src/driver/better-sqlite3/BetterSqlite3QueryRunner.ts index d7fcc8adaa..5375fa5ecd 100644 --- a/src/driver/better-sqlite3/BetterSqlite3QueryRunner.ts +++ b/src/driver/better-sqlite3/BetterSqlite3QueryRunner.ts @@ -4,6 +4,7 @@ import { AbstractSqliteQueryRunner } from "../sqlite-abstract/AbstractSqliteQuer import { Broadcaster } from "../../subscriber/Broadcaster" import { BetterSqlite3Driver } from "./BetterSqlite3Driver" import { QueryResult } from "../../query-runner/QueryResult" +import { BroadcasterResult } from "../../subscriber/BroadcasterResult" /** * Runs queries on a single sqlite database connection. @@ -83,7 +84,14 @@ export class BetterSqlite3QueryRunner extends AbstractSqliteQueryRunner { const connection = this.driver.connection + const broadcasterResult = new BroadcasterResult() + this.driver.connection.logger.logQuery(query, parameters, this) + this.broadcaster.broadcastBeforeQueryEvent( + broadcasterResult, + query, + parameters, + ) const queryStartTime = +new Date() const stmt = await this.getStmt(query) @@ -121,6 +129,16 @@ export class BetterSqlite3QueryRunner extends AbstractSqliteQueryRunner { this, ) + this.broadcaster.broadcastAfterQueryEvent( + broadcasterResult, + query, + parameters, + true, + queryExecutionTime, + result.raw, + undefined, + ) + if (!useStructuredResult) { return result.raw } diff --git a/src/driver/postgres/PostgresQueryRunner.ts b/src/driver/postgres/PostgresQueryRunner.ts index fae9704985..481cf4943c 100644 --- a/src/driver/postgres/PostgresQueryRunner.ts +++ b/src/driver/postgres/PostgresQueryRunner.ts @@ -601,10 +601,22 @@ export class PostgresQueryRunner downQueries.push(this.dropIndexSql(table, index)) }) } - + if (table.comment) { - upQueries.push(new Query("COMMENT ON TABLE " + this.escapePath(table) + " IS '" + table.comment + "'")); - downQueries.push(new Query("COMMENT ON TABLE " + this.escapePath(table) + " IS NULL")); + upQueries.push( + new Query( + "COMMENT ON TABLE " + + this.escapePath(table) + + " IS '" + + table.comment + + "'", + ), + ) + downQueries.push( + new Query( + "COMMENT ON TABLE " + this.escapePath(table) + " IS NULL", + ), + ) } await this.executeQueries(upQueries, downQueries) @@ -4744,7 +4756,7 @@ export class PostgresQueryRunner newComment = this.escapeComment(newComment) const comment = this.escapeComment(table.comment) - + if (newComment === comment) { return } diff --git a/src/query-builder/InsertQueryBuilder.ts b/src/query-builder/InsertQueryBuilder.ts index 1acc3304ac..52a906f789 100644 --- a/src/query-builder/InsertQueryBuilder.ts +++ b/src/query-builder/InsertQueryBuilder.ts @@ -459,10 +459,8 @@ export class InsertQueryBuilder< // add VALUES expression if (valuesExpression) { if ( - ( - this.connection.driver.options.type === "oracle" || - this.connection.driver.options.type === "sap" - ) && + (this.connection.driver.options.type === "oracle" || + this.connection.driver.options.type === "sap") && this.getValueSets().length > 1 ) { query += ` ${valuesExpression}` diff --git a/src/query-builder/QueryBuilder.ts b/src/query-builder/QueryBuilder.ts index 289f3e3d04..8953cd895f 100644 --- a/src/query-builder/QueryBuilder.ts +++ b/src/query-builder/QueryBuilder.ts @@ -522,7 +522,10 @@ export abstract class QueryBuilder { * Uses same query runner as current QueryBuilder. */ createQueryBuilder(queryRunner?: QueryRunner): this { - return new (this.constructor as any)(this.connection, queryRunner ?? this.queryRunner) + return new (this.constructor as any)( + this.connection, + queryRunner ?? this.queryRunner, + ) } /** diff --git a/src/schema-builder/RdbmsSchemaBuilder.ts b/src/schema-builder/RdbmsSchemaBuilder.ts index 9b22d95358..1f5460e3f5 100644 --- a/src/schema-builder/RdbmsSchemaBuilder.ts +++ b/src/schema-builder/RdbmsSchemaBuilder.ts @@ -604,7 +604,7 @@ export class RdbmsSchemaBuilder implements SchemaBuilder { if ( DriverUtils.isMySQLFamily(this.connection.driver) || - this.connection.driver.options.type === 'postgres' + this.connection.driver.options.type === "postgres" ) { const newComment = metadata.comment await this.queryRunner.changeTableComment(table, newComment) diff --git a/test/integration/sample2-one-to-one.ts b/test/integration/sample2-one-to-one.ts index ce780e3d78..24f18452d2 100644 --- a/test/integration/sample2-one-to-one.ts +++ b/test/integration/sample2-one-to-one.ts @@ -211,14 +211,15 @@ describe("one-to-one", function () { expectedPost.details!.comment = savedPost.details!.comment expectedPost.details!.metadata = savedPost.details!.metadata - const findOne = () => postRepository.findOne({ + const findOne = () => + postRepository.findOne({ where: { - id: savedPost.id + id: savedPost.id, }, relations: { - details: true + details: true, }, - relationLoadStrategy: "query" + relationLoadStrategy: "query", }) const posts = await Promise.all([ @@ -234,7 +235,7 @@ describe("one-to-one", function () { findOne(), ]) - posts.forEach(post => { + posts.forEach((post) => { expect(post).not.to.be.null post!.should.eql(expectedPost) }) diff --git a/test/integration/sample3-many-to-one.ts b/test/integration/sample3-many-to-one.ts index b6b4783eb1..a2f0580547 100644 --- a/test/integration/sample3-many-to-one.ts +++ b/test/integration/sample3-many-to-one.ts @@ -213,15 +213,16 @@ describe("many-to-one", function () { expectedPost.details!.comment = savedPost.details!.comment expectedPost.details!.metadata = savedPost.details!.metadata - const findOne = () => postRepository.findOne({ - where: { - id: savedPost.id - }, - relations: { - details: true - }, - relationLoadStrategy: "query" - }) + const findOne = () => + postRepository.findOne({ + where: { + id: savedPost.id, + }, + relations: { + details: true, + }, + relationLoadStrategy: "query", + }) const posts = await Promise.all([ findOne(), @@ -236,7 +237,7 @@ describe("many-to-one", function () { findOne(), ]) - posts.forEach(post => { + posts.forEach((post) => { expect(post).not.to.be.null post!.should.eql(expectedPost) })