Skip to content

Commit c230d80

Browse files
authored
feat(oracle): add oracle dialect support (#14638)
* feat(oracle): add oracle dialect support (#1) * feat(oracle): add oracle dialect support * fix: addressing review comments (#7) * fix: addressing review comments * fix: minor fixes done (#9) * fix: minor fixes to the review comments * fix: merge from sequelize-v6 * fix: enable newly added unit tests for Oracle dialect * fix: remove dangling comma (#13) * fix: doc gen is fixed * fix: autogenerate the primary constraint name (#14) * fix: autogenerate the primary constraint name * fix: remove trailing comma * fix: make changes to ORADERBY as per v6 sync * fix: move test-unit-oracle above test-unit-all * fix: rename getInsertQueryReturnIntoBinds to populateInsertQueryReturnIntoBinds * fix: reorder parameters for function populateInsertQueryReturnIntoBinds * fix: incorporated review comments (#16) * fix: incorporated review comments * fix: modify string empty check with !
1 parent 33d94b2 commit c230d80

File tree

79 files changed

+3677
-191
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+3677
-191
lines changed

.github/workflows/ci.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,34 @@ jobs:
4747
- run: yarn install --frozen-lockfile
4848
- run: yarn add --dev typescript@~${{ matrix.ts-version }}
4949
- run: yarn test-typings
50+
test-oracle:
51+
strategy:
52+
fail-fast: false
53+
matrix:
54+
node-version: [10, 18]
55+
name: Oracle DB (Node ${{ matrix.node-version }})
56+
runs-on: ubuntu-latest
57+
env:
58+
DIALECT: oracle
59+
SEQ_ORACLE_USER: sequelizetest
60+
SEQ_ORACLE_PW: sequelizepassword
61+
SEQ_ORACLE_DB: XEPDB1
62+
SEQ_ORACLE_HOST: localhost
63+
SEQ_ORACLE_PORT: 1521
64+
LD_LIBRARY_PATH: ${{ github.workspace }}/.oracle/instantclient
65+
UV_THREADPOOL_SIZE: 128
66+
steps:
67+
- uses: actions/checkout@v3
68+
- uses: actions/setup-node@v3
69+
with:
70+
node-version: ${{ matrix.node-version }}
71+
- run: yarn install --frozen-lockfile --ignore-engines
72+
- name: Install Local Oracle DB
73+
run: yarn start-oracle
74+
- name: Unit Tests
75+
run: yarn test-unit
76+
- name: Integration Tests
77+
run: yarn test-integration
5078
test-db2:
5179
strategy:
5280
fail-fast: false

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ esdoc
1616
node_modules
1717
/lib
1818
/types
19+
.oracle/
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved
2+
3+
services:
4+
oraclexedb:
5+
container_name: oraclexedb
6+
image: gvenzl/oracle-xe:21-slim
7+
environment:
8+
ORACLE_PASSWORD: password
9+
ports:
10+
- 1521:1521
11+
healthcheck:
12+
test: ["CMD-SHELL", "sqlplus", "system/password@XEPDB1"]
13+
retries: 10
14+
15+
networks:
16+
default:
17+
name: sequelize-oraclexedb-network

dev/oracle/21-slim/privileges.sql

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
-- Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved
2+
3+
create user sequelizetest identified by sequelizepassword;
4+
grant connect to sequelizetest with admin option;
5+
grant create session to sequelizetest with admin option;
6+
grant grant any privilege to sequelizetest with admin option;
7+
grant grant any role to sequelizetest with admin option;
8+
grant create any table to sequelizetest with admin option;
9+
grant insert any table to sequelizetest with admin option;
10+
grant select any table to sequelizetest with admin option;
11+
grant update any table to sequelizetest with admin option;
12+
grant delete any table to sequelizetest with admin option;
13+
grant drop any table to sequelizetest with admin option;
14+
grant create view to sequelizetest with admin option;
15+
grant create user to sequelizetest with admin option;
16+
grant drop user to sequelizetest with admin option;
17+
grant create any trigger to sequelizetest with admin option;
18+
grant create any procedure to sequelizetest with admin option;
19+
grant create any sequence to sequelizetest with admin option;
20+
grant select any sequence to sequelizetest with admin option;
21+
grant drop any sequence to sequelizetest with admin option;
22+
grant create any synonym to sequelizetest with admin option;
23+
grant create any index to sequelizetest with admin option;
24+
grant alter user to sequelizetest with admin option;
25+
grant alter any table to sequelizetest with admin option;
26+
alter user sequelizetest quota unlimited on users;
27+
exit;

dev/oracle/21-slim/start.sh

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved
2+
3+
#!/usr/bin/env bash
4+
set -Eeuxo pipefail # https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/
5+
cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" # https://stackoverflow.com/a/17744637
6+
7+
# Remove an existing Oracle DB docker image
8+
docker-compose -p oraclexedb down --remove-orphans
9+
10+
# Bring up new Oracle DB docker image
11+
docker-compose -p oraclexedb up -d
12+
13+
# Wait until Oracle DB is set up and docker state is healthy
14+
./wait-until-healthy.sh oraclexedb
15+
16+
# Moving privileges.sql to docker container
17+
docker cp privileges.sql oraclexedb:/opt/oracle/.
18+
19+
# Granting all the needed privileges to sequelizetest user
20+
docker exec -t oraclexedb sqlplus system/password@XEPDB1 @privileges.sql
21+
22+
SEQ_WORKSPACE="$PWD"/../../../
23+
24+
if [[ ! -d "$SEQ_WORKSPACE"/.oracle/ ]]
25+
then
26+
mkdir "$SEQ_WORKSPACE"/.oracle/
27+
if [[ $(uname) == 'Linux' ]]
28+
then
29+
wget https://download.oracle.com/otn_software/linux/instantclient/216000/instantclient-basic-linux.x64-21.6.0.0.0dbru.zip --no-check-certificate &&
30+
unzip instantclient-basic-linux.x64-21.6.0.0.0dbru.zip -d "$SEQ_WORKSPACE"/.oracle/ &&
31+
rm instantclient-basic-linux.x64-21.6.0.0.0dbru.zip &&
32+
mv "$SEQ_WORKSPACE"/.oracle/instantclient_21_6 "$SEQ_WORKSPACE"/.oracle/instantclient
33+
34+
echo "Local Oracle instant client on Linux has been setup!"
35+
elif [[ $(uname) == 'Darwin' ]]
36+
then
37+
if [[ ! -d ~/Downloads/instantclient_19_8 ]]
38+
then
39+
curl -O https://download.oracle.com/otn_software/mac/instantclient/198000/instantclient-basic-macos.x64-19.8.0.0.0dbru.dmg &&
40+
hdiutil mount instantclient-basic-macos.x64-19.8.0.0.0dbru.dmg &&
41+
/Volumes/instantclient-basic-macos.x64-19.8.0.0.0dbru/install_ic.sh &&
42+
hdiutil unmount /Volumes/instantclient-basic-macos.x64-19.8.0.0.0dbru &&
43+
rm instantclient-basic-macos.x64-19.8.0.0.0dbru.dmg &&
44+
mv ~/Downloads/instantclient_19_8/ "$SEQ_WORKSPACE"/.oracle/instantclient
45+
else
46+
cp -rf ~/Downloads/instantclient_19_8/ "$SEQ_WORKSPACE"/.oracle/instantclient
47+
fi
48+
ln -s "$SEQ_WORKSPACE"/.oracle/instantclient/libclntsh.dylib "$SEQ_WORKSPACE"/node_modules/oracledb/build/Release/
49+
50+
echo "Local Oracle instant client on macOS has been setup!"
51+
else
52+
# Windows
53+
curl -O https://download.oracle.com/otn_software/nt/instantclient/216000/instantclient-basic-windows.x64-21.6.0.0.0dbru.zip &&
54+
unzip instantclient-basic-windows.x64-21.6.0.0.0dbru.zip -d "$SEQ_WORKSPACE"/.oracle/ &&
55+
rm instantclient-basic-windows.x64-21.6.0.0.0dbru.zip &&
56+
mv "$SEQ_WORKSPACE"/.oracle/instantclient_21_6/* "$SEQ_WORKSPACE"/node_modules/oracledb/build/Release
57+
58+
echo "Local Oracle instant client on $(uname) has been setup!"
59+
fi
60+
fi
61+
echo "Local Oracle DB is ready for use!"

dev/oracle/21-slim/stop.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved
2+
3+
#!/usr/bin/env bash
4+
set -Eeuxo pipefail # https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/
5+
cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" # https://stackoverflow.com/a/17744637
6+
7+
8+
docker-compose -p oraclexedb down --remove-orphans
9+
10+
echo "Local Oracle DB instance stopped (if it was running)."
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
3+
if [ "$#" -ne 1 ]; then
4+
>&2 echo "Please provide the container name or hash"
5+
exit 1
6+
fi
7+
8+
for _ in {1..50}
9+
do
10+
state=$(docker inspect -f '{{ .State.Health.Status }}' $1 2>&1)
11+
return_code=$?
12+
if [ ${return_code} -eq 0 ] && [ "$state" == "healthy" ]; then
13+
echo "$1 is healthy!"
14+
sleep 60
15+
exit 0
16+
fi
17+
sleep 6
18+
done
19+
20+
>&2 echo "Timeout of 5m exceeded when waiting for container to be healthy: $1"
21+
exit 1

package.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
"mysql2": "^2.3.3",
107107
"node-hook": "^1.0.0",
108108
"nyc": "^15.1.0",
109+
"oracledb": "^5.4.0",
109110
"p-map": "^4.0.0",
110111
"p-props": "^4.0.0",
111112
"p-settle": "^4.1.1",
@@ -147,6 +148,9 @@
147148
},
148149
"tedious": {
149150
"optional": true
151+
},
152+
"oracledb": {
153+
"optional": true
150154
}
151155
},
152156
"keywords": [
@@ -160,6 +164,7 @@
160164
"db2",
161165
"ibm_db",
162166
"sql",
167+
"oracledb",
163168
"sqlserver",
164169
"snowflake",
165170
"orm",
@@ -239,17 +244,20 @@
239244
"start-postgres": "bash dev/postgres/10/start.sh",
240245
"start-mssql": "bash dev/mssql/2019/start.sh",
241246
"start-db2": "bash dev/db2/11.5/start.sh",
247+
"start-oracle": "bash dev/oracle/21-slim/start.sh",
242248
"stop-mariadb": "bash dev/mariadb/10.3/stop.sh",
243249
"stop-mysql": "bash dev/mysql/5.7/stop.sh",
244250
"stop-mysql-8": "bash dev/mysql/8.0/stop.sh",
245251
"stop-postgres": "bash dev/postgres/10/stop.sh",
246252
"stop-mssql": "bash dev/mssql/2019/stop.sh",
247253
"stop-db2": "bash dev/db2/11.5/stop.sh",
254+
"stop-oracle": "bash dev/oracle/21-slim/stop.sh",
248255
"restart-mariadb": "npm run start-mariadb",
249256
"restart-mysql": "npm run start-mysql",
250257
"restart-postgres": "npm run start-postgres",
251258
"restart-mssql": "npm run start-mssql",
252259
"restart-db2": "npm run start-db2",
260+
"restart-oracle": "npm run start-oracle",
253261
"----------------------------------------- local tests ---------------------------------------------": "",
254262
"test-unit-mariadb": "cross-env DIALECT=mariadb npm run test-unit",
255263
"test-unit-mysql": "cross-env DIALECT=mysql npm run test-unit",
@@ -259,7 +267,8 @@
259267
"test-unit-mssql": "cross-env DIALECT=mssql npm run test-unit",
260268
"test-unit-db2": "cross-env DIALECT=db2 npm run test-unit",
261269
"test-unit-snowflake": "cross-env DIALECT=snowflake npm run test-unit",
262-
"test-unit-all": "npm run test-unit-mariadb && npm run test-unit-mysql && npm run test-unit-postgres && npm run test-unit-postgres-native && npm run test-unit-mssql && npm run test-unit-sqlite && npm run test-unit-snowflake && npm run test-unit-db2",
270+
"test-unit-oracle": "cross-env DIALECT=oracle npm run test-unit",
271+
"test-unit-all": "npm run test-unit-mariadb && npm run test-unit-mysql && npm run test-unit-postgres && npm run test-unit-postgres-native && npm run test-unit-mssql && npm run test-unit-sqlite && npm run test-unit-snowflake && npm run test-unit-db2 && npm run test-unit-oracle",
263272
"test-integration-mariadb": "cross-env DIALECT=mariadb npm run test-integration",
264273
"test-integration-mysql": "cross-env DIALECT=mysql npm run test-integration",
265274
"test-integration-postgres": "cross-env DIALECT=postgres npm run test-integration",
@@ -268,13 +277,15 @@
268277
"test-integration-mssql": "cross-env DIALECT=mssql npm run test-integration",
269278
"test-integration-db2": "cross-env DIALECT=db2 npm run test-integration",
270279
"test-integration-snowflake": "cross-env DIALECT=snowflake npm run test-integration",
280+
"test-integration-oracle": "cross-env LD_LIBRARY_PATH=\"$PWD/.oracle/instantclient/\" DIALECT=oracle UV_THREADPOOL_SIZE=128 npm run test-integration",
271281
"test-mariadb": "cross-env DIALECT=mariadb npm test",
272282
"test-mysql": "cross-env DIALECT=mysql npm test",
273283
"test-sqlite": "cross-env DIALECT=sqlite npm test",
274284
"test-postgres": "cross-env DIALECT=postgres npm test",
275285
"test-postgres-native": "cross-env DIALECT=postgres-native npm test",
276286
"test-mssql": "cross-env DIALECT=mssql npm test",
277287
"test-db2": "cross-env DIALECT=db2 npm test",
288+
"test-oracle": "cross-env LD_LIBRARY_PATH=\"$PWD/.oracle/instantclient/\" DIALECT=oracle UV_THREADPOOL_SIZE=128 npm test",
278289
"----------------------------------------- development ---------------------------------------------": "",
279290
"sscce": "node sscce.js",
280291
"sscce-mariadb": "cross-env DIALECT=mariadb node sscce.js",
@@ -284,6 +295,7 @@
284295
"sscce-sqlite": "cross-env DIALECT=sqlite node sscce.js",
285296
"sscce-mssql": "cross-env DIALECT=mssql node sscce.js",
286297
"sscce-db2": "cross-env DIALECT=db2 node sscce.js",
298+
"sscce-oracle": "cross-env LD_LIBRARY_PATH=\"$PWD/.oracle/instantclient/\" DIALECT=oracle UV_THREADPOOL_SIZE=128 node sscce.js",
287299
"prepare": "npm run build && husky install",
288300
"build": "node ./build.js",
289301
"---------------------------------------------------------------------------------------------------": ""

src/data-types.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,7 @@ dialectMap.sqlite = require('./dialects/sqlite/data-types')(DataTypes);
10601060
dialectMap.mssql = require('./dialects/mssql/data-types')(DataTypes);
10611061
dialectMap.db2 = require('./dialects/db2/data-types')(DataTypes);
10621062
dialectMap.snowflake = require('./dialects/snowflake/data-types')(DataTypes);
1063+
dialectMap.oracle = require('./dialects/oracle/data-types')(DataTypes);
10631064

10641065
const dialectList = Object.values(dialectMap);
10651066

0 commit comments

Comments
 (0)