diff --git a/.env b/.env index 31ad2276..c2504c93 100644 --- a/.env +++ b/.env @@ -1,12 +1,12 @@ DB=pg DB_NAME=lucid -MYSQL_HOST=0.0.0.0 +MYSQL_HOST=mysql MYSQL_PORT=3306 MYSQL_USER=virk MYSQL_PASSWORD=password -PG_HOST=0.0.0.0 +PG_HOST=pg PG_PORT=5432 PG_USER=virk PG_PASSWORD=password diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..2b02858f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +FROM node:10.15.3-alpine as build-deps + +RUN apk update && apk upgrade && \ + apk add --update git && \ + apk add --update openssh && \ + apk add --update bash && \ + apk add --update wget + +WORKDIR /usr/src/app + +COPY package*.json ./ +RUN npm install + +RUN wget https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh -O /wait-for-it.sh +RUN chmod +x /wait-for-it.sh + +COPY . . +RUN npm run build diff --git a/docker-compose.yml b/docker-compose.yml index bfa828d9..f8422a18 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,14 @@ -version: '3.3' +version: '3.4' services: - db: + test: + build: + context: . + target: build-deps + links: + - mysql + - pg + command: ["npm", "run", "test:docker"] + mysql: image: mysql:5.7 restart: always environment: diff --git a/index.ts b/index.ts index 31cd942f..28f22d70 100644 --- a/index.ts +++ b/index.ts @@ -1,141 +1,141 @@ -import * as Knex from 'knex' -// // import { join } from 'path' -import { DatabaseQueryBuilderContract } from '@ioc:Adonis/Addons/DatabaseQueryBuilder' - -const knex = Knex({ - client: 'pg', - connection: { - host: '0.0.0.0', - user: 'virk', - password: '', - database: 'directory-service', - }, - pool: { - min: 0, - max: 5, - idleTimeoutMillis: 30000, - }, - useNullAsDefault: true, -}) - -knex() - .from('foo') - .havingIn('f', ['a']) - -// // let i = 0; -// knex['_context'].client.pool.on('destroySuccess', _eventId => { -// // i++ -// console.log( -// knex['_context'].client.pool.numUsed(), -// knex['_context'].client.pool.numFree(), -// knex['_context'].client.pool.numPendingAcquires(), -// ) - -// // if (i === 3) { -// // knex['_context'].client.pool.destroy() -// // } -// }); - -// knex['_context'].client.pool.on('poolDestroySuccess', _resource => { -// console.log('poolDestroySuccess>>>') -// }); - -// // setInterval(() => { -// // console.log('ping') -// // }, 1000) - -// // type User = { -// // id: number, -// // } - -// // console.log(knex.raw(['10']).toQuery()) - -// // knex.schema.createTable('users', (table) => { -// // table.increments('id') -// // table.string('username') -// // table.integer('age') -// // table.timestamps() -// // }).then(() => console.log('created')) - -// // knex.table('users').insert([ -// // { username: 'virk', age: 29 }, { username: 'nikk', age: 28 }, { username: 'prasan', age: 29 }, -// // ]).then(console.log) - -// Promise.all([ -// knex -// .select('*') -// .from('users') -// .debug(true) -// .then((result) => { -// console.log(result) -// }), -// knex -// .select('*') -// .from('users') -// .debug(true) -// .then((result) => { -// console.log(result) -// }), -// knex -// .select('*') -// .from('users') -// .debug(true) -// .then((result) => { -// console.log(result) -// }), -// knex -// .select('*') -// .from('users') -// .debug(true) -// .then((result) => { -// console.log(result) -// }), -// knex -// .select('*') -// .from('users') -// .debug(true) -// .then((result) => { -// console.log(result) -// }), -// ]).then(() => { +// import * as Knex from 'knex' +// // // import { join } from 'path' +// import { DatabaseQueryBuilderContract } from '@ioc:Adonis/Addons/DatabaseQueryBuilder' + +// const knex = Knex({ +// client: 'pg', +// connection: { +// host: '0.0.0.0', +// user: 'virk', +// password: '', +// database: 'directory-service', +// }, +// pool: { +// min: 0, +// max: 5, +// idleTimeoutMillis: 30000, +// }, +// useNullAsDefault: true, // }) -// // knex.transaction().then((trx) => { +// knex() +// .from('foo') +// .havingIn('f', ['a']) + +// // // let i = 0; +// // knex['_context'].client.pool.on('destroySuccess', _eventId => { +// // // i++ +// // console.log( +// // knex['_context'].client.pool.numUsed(), +// // knex['_context'].client.pool.numFree(), +// // knex['_context'].client.pool.numPendingAcquires(), +// // ) + +// // // if (i === 3) { +// // // knex['_context'].client.pool.destroy() +// // // } +// // }); + +// // knex['_context'].client.pool.on('poolDestroySuccess', _resource => { +// // console.log('poolDestroySuccess>>>') +// // }); + +// // // setInterval(() => { +// // // console.log('ping') +// // // }, 1000) + +// // // type User = { +// // // id: number, +// // // } + +// // // console.log(knex.raw(['10']).toQuery()) + +// // // knex.schema.createTable('users', (table) => { +// // // table.increments('id') +// // // table.string('username') +// // // table.integer('age') +// // // table.timestamps() +// // // }).then(() => console.log('created')) + +// // // knex.table('users').insert([ +// // // { username: 'virk', age: 29 }, { username: 'nikk', age: 28 }, { username: 'prasan', age: 29 }, +// // // ]).then(console.log) + +// // Promise.all([ +// // knex +// // .select('*') +// // .from('users') +// // .debug(true) +// // .then((result) => { +// // console.log(result) +// // }), +// // knex +// // .select('*') +// // .from('users') +// // .debug(true) +// // .then((result) => { +// // console.log(result) +// // }), +// // knex +// // .select('*') +// // .from('users') +// // .debug(true) +// // .then((result) => { +// // console.log(result) +// // }), +// // knex +// // .select('*') +// // .from('users') +// // .debug(true) +// // .then((result) => { +// // console.log(result) +// // }), +// // knex +// // .select('*') +// // .from('users') +// // .debug(true) +// // .then((result) => { +// // console.log(result) +// // }), +// // ]).then(() => { // // }) -// // console.log(query.toSQL()) +// // // knex.transaction().then((trx) => { +// // // }) -// // type FilteredKeys = { [P in keyof T]: T[P] extends Function ? never : P }[keyof T] +// // // console.log(query.toSQL()) -// // type GetRefs = T['refs'] extends object ? { -// // [P in keyof T['refs']]: InstanceType[P] -// // } : { -// // [P in FilteredKeys>]: InstanceType[P] -// // } +// // // type FilteredKeys = { [P in keyof T]: T[P] extends Function ? never : P }[keyof T] -// // class BaseModel { -// // public static refs: unknown +// // // type GetRefs = T['refs'] extends object ? { +// // // [P in keyof T['refs']]: InstanceType[P] +// // // } : { +// // // [P in FilteredKeys>]: InstanceType[P] +// // // } -// // public static query ( -// // this: T, -// // ): DatabaseQueryBuilderContract, InstanceType> { -// // return {} as DatabaseQueryBuilderContract, InstanceType> -// // } -// // } +// // // class BaseModel { +// // // public static refs: unknown -// // class User extends BaseModel { -// // public username: string -// // public age: number +// // // public static query ( +// // // this: T, +// // // ): DatabaseQueryBuilderContract, InstanceType> { +// // // return {} as DatabaseQueryBuilderContract, InstanceType> +// // // } +// // // } -// // public castToInt (): number { -// // return 22 -// // } -// // } +// // // class User extends BaseModel { +// // // public username: string +// // // public age: number -// // class Post extends BaseModel { -// // } +// // // public castToInt (): number { +// // // return 22 +// // // } +// // // } -const foo: DatabaseQueryBuilderContract<{ username: string, age: number, email: string }> = {} -foo.whereIn(['username', 'age', 'email'], [ - ['foo', 22, 'a'], ['bar', 22, 'a'], ['virk', 22, 'a'], -]) +// // // class Post extends BaseModel { +// // // } + +// const foo: DatabaseQueryBuilderContract<{ username: string, age: number, email: string }> = {} +// foo.whereIn(['username', 'age', 'email'], [ +// ['foo', 22, 'a'], ['bar', 22, 'a'], ['virk', 22, 'a'], +// ]) diff --git a/package.json b/package.json index 5b931346..743e821b 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,8 @@ "test:sqlite": "DB=sqlite node japaFile.js", "test:mysql": "DB=mysql node japaFile.js", "test:pg": "DB=pg node japaFile.js", - "test": "npm run test:sqlite && npm run test:mysql && npm run test:pg", + "test:docker": "npm run test:sqlite && npm run test:mysql && npm run test:pg", + "test": "docker-compose build && docker-compose run --rm test", "prepublishOnly": "npm run build", "lint": "tslint --project tsconfig.json", "clean": "del build",