Skip to content
This repository has been archived by the owner on Aug 15, 2024. It is now read-only.

Commit

Permalink
Big Bang
Browse files Browse the repository at this point in the history
  • Loading branch information
Genar Trias Ortiz committed May 5, 2021
1 parent f389dc0 commit a63698a
Show file tree
Hide file tree
Showing 19 changed files with 7,014 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module.exports = {
env: {
browser: true,
es2021: true
},
extends: [
'standard'
],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 12,
sourceType: 'module'
},
plugins: [
'@typescript-eslint',
'jest'
],
rules: {},
overrides: [
{
"files": [
"**/*.spec.ts",
],
"env": {
"jest": true
}
}
]
}
21 changes: 21 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Build and publish Docker image

on:
release:
types: [published]

jobs:
push_to_registry:
name: Push Docker image to GitHub Packages
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v2
- name: Push to GitHub Packages
uses: docker/build-push-action@v1
with:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: docker.pkg.github.com
repository: factorialco/data-engine-lite/data-engine-lite
tag_with_ref: true
22 changes: 22 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Lint

on: pull_request

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0

- uses: actions/setup-node@v1
with:
node-version: '12'

- name: NPM or Yarn install with caching
uses: bahmutov/[email protected]

- name: Lint changes between branch and master
run: yarn run lint
22 changes: 22 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Test

on: pull_request

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0

- uses: actions/setup-node@v1
with:
node-version: '12'

- name: NPM or Yarn install with caching
uses: bahmutov/[email protected]

- name: Test between branch and master
run: yarn run test
22 changes: 22 additions & 0 deletions .github/workflows/tsc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Typescript

on: pull_request

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0

- uses: actions/setup-node@v1
with:
node-version: '12'

- name: NPM or Yarn install with caching
uses: bahmutov/[email protected]

- name: Lint changes between branch and master
run: yarn run tsc
104 changes: 104 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM node:14.16.1

MAINTAINER Genar <[email protected]>

COPY . /app

WORKDIR /app

RUN yarn install --frozen-lockfile

ENV NODE_ENV production
ENV API_DOMAIN https://api.example.com

EXPOSE 8080/tcp

ENTRYPOINT ["yarn", "start"]
6 changes: 6 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
presets: [
['@babel/preset-env', {targets: {node: 'current'}}],
'@babel/preset-typescript',
],
};
23 changes: 23 additions & 0 deletions benchmark.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Execute this test plan with drill and this command parameters:
#
# COOKIE='30d8a898120aa83203bea21b89b16ba0' drill --stats --benchmark benchmark.yml
#
# Tune your cookie value first
---
concurrency: 5
base: 'http://localhost:8080'
iterations: 10

plan:
- name: POST query
request:
url: /sql
method: POST
body: '{ "query": "{{ item }}" }'
headers:
Content-Type: 'application/json'
Cookie: '_factorial_session_v2={{ COOKIE }}'
with_items:
- "SELECT 1+1"
- "SELECT * FROM employee"
- "SELECT goal_config_id, name FROM goals_config WHERE goal_config_id > (SELECT COUNT(*) - 100 FROM employee) AND 1=1"
20 changes: 20 additions & 0 deletions cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import yargs from 'yargs/yargs'
import queryTables from './src/queryTables'

const argv = yargs(process.argv.slice(2)).options({
query: { type: 'string', demandOption: true }
}).argv

if (argv.query) {
const headers = { Cookie: `${process.env.COOKIE}` }

queryTables(
argv.query,
[],
headers
).then(result => {
console.log(result)
}).catch(error => {
console.log(error)
})
}
48 changes: 48 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"name": "data-engine-lite",
"version": "1.0.0",
"description": "Factorial SQL engine",
"dependencies": {
"better-sqlite3": "^7.1.5",
"fastify": "^3.14.2",
"node-fetch": "^2.6.1",
"pino": "^6.11.3",
"sqlite-parser": "^1.0.1",
"yargs": "^16.2.0"
},
"devDependencies": {
"@babel/core": "^7.13.16",
"@babel/preset-env": "^7.13.15",
"@babel/preset-typescript": "^7.13.0",
"@types/better-sqlite3": "^5.4.1",
"@types/jest": "^26.0.23",
"@types/node": "^14.14.41",
"@types/node-fetch": "^2.5.10",
"@types/yargs": "^16.0.1",
"@typescript-eslint/eslint-plugin": "^4.22.0",
"@typescript-eslint/parser": "^4.22.0",
"eslint": "^7.25.0",
"eslint-config-standard": "^16.0.2",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jest": "^24.3.6",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.3.1",
"esno": "^0.5.0",
"jest": "^26.6.3",
"pino-pretty": "^4.7.1",
"rimraf": "^3.0.2",
"tsup": "^4.9.1",
"typescript": "^4.2.4"
},
"scripts": {
"build": "rimraf dist && tsup src/queryTables.ts --format cjs,esm --dts",
"cli": "LOG_LEVEL='debug' esno cli.ts",
"lint": "eslint . --ext .ts",
"start": "esno server.ts",
"test": "jest",
"test:watch": "jest --watch",
"watch": "yarn build -- --watch"
},
"author": "",
"license": "ISC"
}
43 changes: 43 additions & 0 deletions server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import fastify from 'fastify'
import queryTables from './src/queryTables'
import logger from './src/logger'

const server = fastify({ logger: logger })

interface Body {
query: string
parameters?: Array<string>
}

// SQL Query endpoint
server.post<{ Body: Body }>('/sql', (request, reply) => {
return queryTables(
request.body.query,
request.body.parameters || [],
request.headers
).then(result => {
server.log.info(result)

reply.send(result)
}).catch(error => {
server.log.error(error)

reply.send(error)
})
})

// Health check route
server.get('/health-check', async (request, reply) => {
return 'OK'
})

const start = async () => {
try {
await server.listen(process.env.PORT || 8080, '0.0.0.0')
} catch (err) {
server.log.error(err)
process.exit(1)
}
}

start()
Loading

0 comments on commit a63698a

Please sign in to comment.