Skip to content

Commit

Permalink
sapase
Browse files Browse the repository at this point in the history
  • Loading branch information
Lars-Erik Roald committed Dec 30, 2022
1 parent 12d82b5 commit 06c993b
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 38 deletions.
3 changes: 3 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ FROM node:18-alpine
#alpine
RUN apk update
RUN apk add git
RUN apk add libnsl
RUN apk add gcompat
RUN ln -s /usr/lib/libnsl.so.3 /usr/lib/libnsl.so.1
RUN apk --no-cache add curl
RUN apk add sudo
# odbc alpine
Expand Down
1 change: 1 addition & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ services:
ports:
- 50000:5000
tty: true
entrypoint: "/home/sybase/bin/entrypoint.sh"
restart: always
10 changes: 10 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ jobs:
--health-interval=10s
--health-timeout=5s
--health-retries=3
sapase:
image: larsroald/ase-server
hostname: sapase
ports:
- 5000:5000
tty: true
entrypoint: "/home/sybase/bin/entrypoint.sh"
strategy:
matrix:
node-version: [14.x, 16.x, 18.x]
Expand All @@ -62,6 +69,9 @@ jobs:
node-version: ${{ matrix.node-version }}
- run: apk update
- run: apk --no-cache add curl
- run: RUN apk add libnsl
- run: RUN apk add gcompat
- run: RUN ln -s /usr/lib/libnsl.so.3 /usr/lib/libnsl.so.1
- run: apk add sudo
- run: curl -O https://download.microsoft.com/download/b/9/f/b9f3cce4-3925-46d4-9f46-da08869c6486/msodbcsql18_18.1.1.1-1_amd64.apk
- run: curl -O https://download.microsoft.com/download/b/9/f/b9f3cce4-3925-46d4-9f46-da08869c6486/mssql-tools18_18.1.1.1-1_amd64.apk
Expand Down
3 changes: 2 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*Spec
tests
.vscode
.vscode
.devcontainer
85 changes: 85 additions & 0 deletions tests/initSap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
const sql = `
IF
EXISTS (SELECT 1 FROM
sysobjects WHERE type = 'U' and name = 'orderLine')
BEGIN
DROP TABLE orderLine
END
GO
IF
EXISTS (SELECT 1 FROM
sysobjects WHERE type = 'U' and name = 'deliveryAddress')
BEGIN
DROP TABLE deliveryAddress
END
GO
IF
EXISTS (SELECT 1 FROM
sysobjects WHERE type = 'U' and name = '_order')
BEGIN
DROP TABLE _order
END
GO
IF
EXISTS (SELECT 1 FROM
sysobjects WHERE type = 'U' and name = 'customer')
BEGIN
DROP TABLE customer
END
GO
CREATE TABLE customer (
id int IDENTITY PRIMARY KEY,
name TEXT,
balance NUMERIC,
isActive BIT
)
GO
CREATE TABLE _order (
id int IDENTITY PRIMARY KEY,
orderDate DATETIME,
customerId INTEGER REFERENCES customer
)
GO
CREATE TABLE orderLine (
id int IDENTITY PRIMARY KEY,
orderId INTEGER REFERENCES _order,
product TEXT
)
GO
CREATE TABLE deliveryAddress (
id int IDENTITY PRIMARY KEY,
orderId INTEGER REFERENCES _order,
name TEXT,
street TEXT,
postalCode TEXT,
postalPlace TEXT,
countryCode TEXT
)
`;

module.exports = async function(db) {
const statements = sql.split('GO')
for (let i = 0; i < statements.length; i++) {
await db.query(statements[i]);
}
};
83 changes: 46 additions & 37 deletions tests/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,20 @@ const initPg = require('./initPg');
const initMs = require('./initMs');
const initMysql = require('./initMysql');
const initSqlite = require('./initSqlite');
const initSap = require('./initSap');
const dateToISOString = require('../src/dateToISOString');

function pg() {
return rdb.pg('postgres://postgres:postgres@postgres/postgres');
}

function mssql() {
return rdb.mssql('server=mssql;Database=master;Trusted_Connection=No;Uid=sa;pwd=P@assword123;Driver={ODBC Driver 18 for SQL Server};TrustServerCertificate=yes');
}

function mysql() {
return rdb.mySql('mysql://test:test@mysql/test');
}

function sqlite() {
return rdb.sqlite(`demo${new Date().getUTCMilliseconds()}.db`);
}

describe('transaction', () => {

test('pg', async () => await verify(pg(), initPg));
test('mssql', async () => await verify(mssql(), initMs));
test('mysql', async () => await verify(mysql(), initMysql));
test('sqlite', async () => await verify(sqlite(), initSqlite));
test('pg', async () => await verify(pg()));
test('mssql', async () => await verify(mssql()));
test('mysql', async () => await verify(mysql()));
test('sqlite', async () => await verify(sqlite()));
test('sap', async () => await verify(sap()));

async function verify(pool, _initDb) {
const db = _db({ db: pool });

async function verify({pool}) {
const db = _db({db: pool});
let result;
await db.transaction(async (db) => {
result = await db.query('select 1 as foo');
Expand All @@ -41,16 +28,17 @@ describe('transaction', () => {
});


describe('insert autoincremental foo bar', () => {
describe('insert autoincremental', () => {

test('pg', async () => await verify(pg(), initPg));
test('mssql', async () => await verify(mssql(), initMs));
test('mysql', async () => await verify(mysql(), initMysql));
test('sqlite', async () => await verify(sqlite(), initSqlite));
test('pg', async () => await verify(pg()));
test('mssql', async () => await verify(mssql()));
test('mysql', async () => await verify(mysql()));
test('sqlite', async () => await verify(sqlite()));
test('sap', async () => await verify(sap()));

async function verify(pool, initDb) {
const db = _db({ db: pool });
await initDb(db);
async function verify({pool, init}) {
const db = _db({db: pool});
await init(db);

const george = await db.customer.insert({
name: 'George',
Expand All @@ -70,14 +58,15 @@ describe('insert autoincremental foo bar', () => {
});

describe('insert autoincremental with relations', () => {
test('pg', async () => await verify(pg(), initPg));
test('mssql', async () => await verify(mssql(), initMs));
test('mysql', async () => await verify(mysql(), initMysql));
test('sqlite', async () => await verify(sqlite(), initSqlite));
test('pg', async () => await verify(pg()));
test('mssql', async () => await verify(mssql()));
test('mysql', async () => await verify(mysql()));
test('sqlite', async () => await verify(sqlite()));
test('sap', async () => await verify(sap()));

async function verify(pool, initDb) {
async function verify({pool, init}) {
const db = _db({ db: pool });
await initDb(db);
await init(db);

const date1 = new Date(2022, 0, 11, 9, 24, 47);
const date2 = new Date(2021, 0, 11, 12, 22, 45);
Expand Down Expand Up @@ -178,4 +167,24 @@ describe('insert autoincremental with relations', () => {

}

});
});

function pg() {
return {pool: rdb.pg('postgres://postgres:postgres@postgres/postgres'), init: initPg};
}

function mssql() {
return {pool: rdb.mssql('server=mssql;Database=master;Trusted_Connection=No;Uid=sa;pwd=P@assword123;Driver={ODBC Driver 18 for SQL Server};TrustServerCertificate=yes'), init: initMs};
}

function sap() {
return {pool: rdb.sap(`Driver=${__dirname}/libsybdrvodb.so;SERVER=sapase;Port=5000;UID=sa;PWD=sybase;DATABASE=master`), init: initSap};
}

function mysql() {
return {pool: rdb.mySql('mysql://test:test@mysql/test'), init: initMysql};
}

function sqlite() {
return {pool: rdb.sqlite(`demo${new Date().getUTCMilliseconds()}.db`), init: initSqlite};
}
Binary file added tests/libsybdrvodb.so
Binary file not shown.

0 comments on commit 06c993b

Please sign in to comment.