db2graphql
Advanced tools
Comparing version 0.3.6 to 0.3.7
{ | ||
"name": "db2graphql", | ||
"version": "0.3.6", | ||
"version": "0.3.7", | ||
"description": "Generate Graphql schema based on existing relational database", | ||
@@ -13,3 +13,3 @@ "main": "index.js", | ||
"docs:update": "jsdoc src --debug -d docs -R README.md", | ||
"test": "jest", | ||
"test": "jest --maxWorkers=1 --forceExit --detectOpenHandles", | ||
"watch": "jest --maxWorkers=1 --forceExit --watch --coverage --detectOpenHandles", | ||
@@ -27,2 +27,3 @@ "travis_test": "jest --detectOpenHandles --forceExit --maxWorkers=1 --coverage --coverageReporters=text-lcov | coveralls" | ||
"dependencies": { | ||
"lru-cache": "^5.1.1", | ||
"string-hash-64": "^1.0.3" | ||
@@ -29,0 +30,0 @@ }, |
@@ -5,4 +5,8 @@ # db2graphql | ||
[![Build Status](https://travis-ci.org/taviroquai/db2graphql.svg?branch=master)](https://travis-ci.org/taviroquai/db2graphql) | ||
[![Coverage Status](https://coveralls.io/repos/github/taviroquai/db2graphql/badge.svg?branch=master)](https://coveralls.io/github/taviroquai/db2graphql?branch=master) | ||
[![NPM Version Badge](https://img.shields.io/npm/v/db2graphql.svg)](https://www.npmjs.com/package/db2graphql) | ||
[![Build Status Badge](https://travis-ci.org/taviroquai/db2graphql.svg?branch=master)](https://travis-ci.org/taviroquai/db2graphql) | ||
[![Coverage Status Badge](https://coveralls.io/repos/github/taviroquai/db2graphql/badge.svg?branch=master)](https://coveralls.io/github/taviroquai/db2graphql?branch=master) | ||
![Dependencies Badge](https://img.shields.io/david/taviroquai/db2graphql.svg?style=flat) | ||
![Module Size Badge](https://img.shields.io/bundlephobia/min/db2graphql.svg?style=flat) | ||
![Last Commit Badge](https://img.shields.io/github/last-commit/taviroquai/db2graphql.svg?style=flat) | ||
@@ -20,3 +24,3 @@ :exclamation::exclamation::exclamation: **Warning: don't use this in production yet, but your feedback is very important!** | ||
## Demo | ||
[![link to youtube video](demo/demo.png)](https://www.youtube.com/watch?v=HYwjcqekCuc) | ||
[![link to youtube video](demo/demo.png)](https://youtu.be/OpsLJvfqM6Q) | ||
@@ -69,3 +73,3 @@ ### Query example | ||
const db2g = require('db2graphql'); | ||
const api = new db2g(knex(require('./connection.json'))); | ||
const api = new db2g('demo', knex(require('./connection.json'))); | ||
await api.connect(); | ||
@@ -100,3 +104,3 @@ const schema = api.getSchema(); | ||
/**************************************/ | ||
const api = new db2g(knex(require('./connection.json'))); | ||
const api = new db2g('demo', knex(require('./connection.json'))); | ||
await api.connect(); // Connects to database and extracts database schema | ||
@@ -144,6 +148,6 @@ | ||
const db2g = require('db2graphql'); | ||
const api = new db2g(); | ||
const api = new db2g('demo'); | ||
// Add a query and resolver | ||
api.add('getFoo', 'Boolean', async (root, args, context) => { | ||
api.add('Query', 'getFoo', 'Boolean', async (root, args, context) => { | ||
return true; | ||
@@ -163,5 +167,5 @@ }, { param: 'String!' }); | ||
$ psql -h localhost -U postgres -c "CREATE DATABASE db2graphql" | ||
$ psql -h localhost -U postgres -f demo/database.sql db2graphql | ||
$ cp demo/connection.example.json demo/connection.json | ||
# Edit demo/connection.json | ||
$ npm run demo-db | ||
$ npm run start | ||
@@ -168,0 +172,0 @@ ``` |
const hash = require('string-hash-64'); | ||
const LruCache = require('lru-cache'); | ||
@@ -21,3 +22,3 @@ /** | ||
this.dbSchema = dbSchema; | ||
this.cache = {}; | ||
this.cache = new LruCache({ max: 500, maxAge: 1000 * 60 * 60 * 5 }); | ||
} | ||
@@ -72,6 +73,5 @@ | ||
const key = this.getCacheKey(tablename, 'page', [], args); | ||
if (!this.cache[tablename]) this.cache[tablename] = {}; | ||
if (args._cache !== false && this.cache[tablename][key]) { | ||
if (args._cache !== false && this.cache.peek(key)) { | ||
if (args._debug) console.log('cache hit:', key); | ||
return this.cache[tablename][key]; | ||
return this.cache.get(key); | ||
} | ||
@@ -85,3 +85,3 @@ | ||
const items = await query; | ||
this.cache[tablename][key] = items; | ||
this.cache.set(key, items); | ||
return items; | ||
@@ -260,6 +260,5 @@ } | ||
const key = this.getCacheKey(tablename, 'page', ids, localArgs); | ||
if (!this.cache[tablename]) this.cache[tablename] = {}; | ||
if (args._cache !== false && this.cache[tablename][key]) { | ||
if (args._cache !== false && this.cache.peek(key)) { | ||
if (args._debug) console.log('cache hit:', key); | ||
return this.cache[tablename][key]; | ||
return this.cache.get(key); | ||
} | ||
@@ -272,3 +271,3 @@ | ||
const results = await query; | ||
this.cache[tablename][key] = results; | ||
this.cache.set(key, results); | ||
return results; | ||
@@ -275,0 +274,0 @@ } |
153016
176
2
2393
+ Addedlru-cache@^5.1.1
+ Addedlru-cache@5.1.1(transitive)
+ Addedyallist@3.1.1(transitive)