Skip to content

Commit

Permalink
fix: multi patch raw false (#436)
Browse files Browse the repository at this point in the history
* test: add tests for raw

* test: pass process.env.DB to connection.ts

* chore: logging for postgres & mysql

* fix: raw: false for multi patch

* test: custom NotFound with integer

* chore: gh actions global env

* chore: init mysql gh action

* chore: console.log connection

* chore: rm console.log
  • Loading branch information
fratzinger authored May 13, 2024
1 parent df848da commit eb57f7c
Show file tree
Hide file tree
Showing 6 changed files with 329 additions and 28 deletions.
34 changes: 30 additions & 4 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ name: CI

on: [push, pull_request]

env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: sequelize

MYSQL_USER: sequelize
MYSQL_DATABASE: sequelize
MYSQL_PASSWORD: password

jobs:
build:

Expand All @@ -11,18 +20,35 @@ jobs:
postgres:
image: postgres:12.12
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: sequelize
POSTGRES_USER: ${{ env.POSTGRES_USER }}
POSTGRES_PASSWORD: ${{ env.POSTGRES_PASSWORD }}
POSTGRES_DB: ${{ env.POSTGRES_DB }}
ports:
- 5432:5432
# needed because the postgres container does not provide a healthcheck
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

mysql:
image: mysql:8.4
env:
# The MySQL docker container requires these environment variables to be set
# so we can create and migrate the test database.
# See: https://hub.docker.com/_/mysql
MYSQL_DATABASE: ${{ env.MYSQL_DATABASE }}
MYSQL_ROOT_PASSWORD: ${{ env.MYSQL_PASSWORD }}
MYSQL_USER: ${{ env.MYSQL_USER }}
MYSQL_PASSWORD: ${{ env.MYSQL_PASSWORD }}
ports:
# Opens port 3306 on service container and host
# https://docs.github.com/en/actions/using-containerized-services/about-service-containers
- 3306:3306
# Before continuing, verify the mysql container is reachable from the ubuntu host
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries 5

strategy:
matrix:
node-version: [18.x, 20.x, 22.x]
database: ['sqlite', 'postgres']
database: ['sqlite', 'postgres', 'mysql']

steps:
- uses: actions/checkout@v3
Expand Down
1 change: 1 addition & 0 deletions src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ export class SequelizeAdapter<
let [, instances] = await Model
.update(values, {
...sequelizeOptions,
raw: false,
where: { [this.id]: ids.length === 1 ? ids[0] : { [Op.in]: ids } }
} as UpdateOptions)
.catch(errorHandler) as [number, Model[]?];
Expand Down
35 changes: 25 additions & 10 deletions test/connection.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,36 @@
import type { Options } from 'sequelize';
import { Sequelize } from 'sequelize';

export default (DB?: 'postgres' | 'mysql') => {
export default (DB?: 'postgres' | 'mysql' | string) => {
const logging: Options['logging'] = false;

if (DB === 'postgres') {
return new Sequelize('sequelize', 'postgres', 'password', {
host: 'localhost',
dialect: 'postgres'
});
return new Sequelize(
process.env.POSTGRES_DB ?? 'sequelize',
process.env.POSTGRES_USER ?? 'postgres',
process.env.POSTGRES_PASSWORD ?? 'password',
{
host: 'localhost',
dialect: 'postgres',
logging
}
);
} else if (DB === 'mysql') {
return new Sequelize('sequelize', 'root', '', {
host: '127.0.0.1',
dialect: 'mysql'
});
return new Sequelize(
process.env.MYSQl_DATABASE ?? 'sequelize',
process.env.MYSQL_USER ?? 'root',
process.env.MYSQL_PASSWORD ?? '',
{
host: '127.0.0.1',
dialect: 'mysql',
logging
}
);
} else {
return new Sequelize('sequelize', '', '', {
dialect: 'sqlite',
storage: './db.sqlite',
logging: false
logging
});
}
};
2 changes: 1 addition & 1 deletion test/hooks.dehydrate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Sequelize from 'sequelize';

import { dehydrate } from '../src/hooks/dehydrate';
import makeConnection from './connection';
const sequelize = makeConnection();
const sequelize = makeConnection(process.env.DB);

type MethodName = 'find' | 'get' | 'create' | 'update' | 'patch' | 'remove';

Expand Down
2 changes: 1 addition & 1 deletion test/hooks.hydrate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Sequelize from 'sequelize';

import { hydrate } from '../src/hooks/hydrate';
import makeConnection from './connection'
const sequelize = makeConnection();
const sequelize = makeConnection(process.env.DB);

type MethodName = 'find' | 'get' | 'create' | 'update' | 'patch' | 'remove';

Expand Down
Loading

0 comments on commit eb57f7c

Please sign in to comment.