This repository has been archived by the owner on Aug 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Genar Trias Ortiz
committed
May 5, 2021
1 parent
f389dc0
commit a63698a
Showing
19 changed files
with
7,014 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Oops, something went wrong.