Skip to content

Commit

Permalink
chore: setup tests using docker compose
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Aug 6, 2019
1 parent 3542934 commit 4c8df5e
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 134 deletions.
4 changes: 2 additions & 2 deletions .env
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
12 changes: 10 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
258 changes: 129 additions & 129 deletions index.ts
Original file line number Diff line number Diff line change
@@ -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<T> = { [P in keyof T]: T[P] extends Function ? never : P }[keyof T]
// // // console.log(query.toSQL())

// // type GetRefs<T extends typeof BaseModel> = T['refs'] extends object ? {
// // [P in keyof T['refs']]: InstanceType<T>[P]
// // } : {
// // [P in FilteredKeys<InstanceType<T>>]: InstanceType<T>[P]
// // }
// // // type FilteredKeys<T> = { [P in keyof T]: T[P] extends Function ? never : P }[keyof T]

// // class BaseModel {
// // public static refs: unknown
// // // type GetRefs<T extends typeof BaseModel> = T['refs'] extends object ? {
// // // [P in keyof T['refs']]: InstanceType<T>[P]
// // // } : {
// // // [P in FilteredKeys<InstanceType<T>>]: InstanceType<T>[P]
// // // }

// // public static query<T extends typeof BaseModel> (
// // this: T,
// // ): DatabaseQueryBuilderContract<GetRefs<T>, InstanceType<T>> {
// // return {} as DatabaseQueryBuilderContract<GetRefs<T>, InstanceType<T>>
// // }
// // }
// // // class BaseModel {
// // // public static refs: unknown

// // class User extends BaseModel {
// // public username: string
// // public age: number
// // // public static query<T extends typeof BaseModel> (
// // // this: T,
// // // ): DatabaseQueryBuilderContract<GetRefs<T>, InstanceType<T>> {
// // // return {} as DatabaseQueryBuilderContract<GetRefs<T>, InstanceType<T>>
// // // }
// // // }

// // 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'],
// ])
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 4c8df5e

Please sign in to comment.