pax_global_header 0000666 0000000 0000000 00000000064 14137615212 0014514 g ustar 00root root 0000000 0000000 52 comment=e58617c23456cb07de617f42407c89faca92ace7
keyv-4.0.4/ 0000775 0000000 0000000 00000000000 14137615212 0012477 5 ustar 00root root 0000000 0000000 keyv-4.0.4/.github/ 0000775 0000000 0000000 00000000000 14137615212 0014037 5 ustar 00root root 0000000 0000000 keyv-4.0.4/.github/workflows/ 0000775 0000000 0000000 00000000000 14137615212 0016074 5 ustar 00root root 0000000 0000000 keyv-4.0.4/.github/workflows/build.yaml 0000664 0000000 0000000 00000001534 14137615212 0020062 0 ustar 00root root 0000000 0000000 name: build
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node: [ '12', '14', '16' ]
name: Node ${{ matrix.node }}
steps:
- uses: actions/checkout@v2
- name: Setup node
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node }}
- name: Start Services
run: npm run test:services:start
- name: Install Dependencies
run: npm install
- name: Test Keyv
run: npm test
- name: Test Storage Adapters
run: npm run test:full
- name: Generate Code Coverage Report
run: yarn coverage
- name: Code Coverage
uses: codecov/codecov-action@v1.0.15
with:
token: ${{ secrets.CODECOV_KEY }} keyv-4.0.4/.gitignore 0000664 0000000 0000000 00000002114 14137615212 0014465 0 ustar 00root root 0000000 0000000 test/testdb.sqlite
## Node
#npm5
package-lock.json
#yarn
yarn.lock
# Logs
logs
*.log
npm-debug.log*
# 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
# nyc test coverage
.nyc_output
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# node-waf configuration
.lock-wscript
# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules
jspm_packages
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional REPL history
.node_repl_history
## OS X
*.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
keyv-4.0.4/.npmignore 0000664 0000000 0000000 00000000007 14137615212 0014473 0 ustar 00root root 0000000 0000000 *
!src
keyv-4.0.4/.nvmrc 0000664 0000000 0000000 00000000002 14137615212 0013615 0 ustar 00root root 0000000 0000000 16 keyv-4.0.4/LICENSE 0000664 0000000 0000000 00000002076 14137615212 0013511 0 ustar 00root root 0000000 0000000 MIT License
Copyright (c) 2017-2021 Jared Wray & Luke Childs
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
keyv-4.0.4/README.md 0000664 0000000 0000000 00000025606 14137615212 0013767 0 ustar 00root root 0000000 0000000
> Simple key-value storage with support for multiple backends
[](https://github.com/jaredwray/keyv/actions/workflows/build.yaml)
[](https://codecov.io/gh/jaredwray/keyv)
[](https://www.npmjs.com/package/keyv)
[](https://www.npmjs.com/package/keyv)
Keyv provides a consistent interface for key-value storage across multiple backends via storage adapters. It supports TTL based expiry, making it suitable as a cache or a persistent key-value store.
## Features
There are a few existing modules similar to Keyv, however Keyv is different because it:
- Isn't bloated
- Has a simple Promise based API
- Suitable as a TTL based cache or persistent key-value store
- [Easily embeddable](#add-cache-support-to-your-module) inside another module
- Works with any storage that implements the [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) API
- Handles all JSON types plus `Buffer`
- Supports namespaces
- Wide range of [**efficient, well tested**](#official-storage-adapters) storage adapters
- Connection errors are passed through (db failures won't kill your app)
- Supports the current active LTS version of Node.js or higher
## Usage
Install Keyv.
```
npm install --save keyv
```
By default everything is stored in memory, you can optionally also install a storage adapter.
```
npm install --save @keyv/redis
npm install --save @keyv/mongo
npm install --save @keyv/sqlite
npm install --save @keyv/postgres
npm install --save @keyv/mysql
```
Create a new Keyv instance, passing your connection string if applicable. Keyv will automatically load the correct storage adapter.
```js
const Keyv = require('keyv');
// One of the following
const keyv = new Keyv();
const keyv = new Keyv('redis://user:pass@localhost:6379');
const keyv = new Keyv('mongodb://user:pass@localhost:27017/dbname');
const keyv = new Keyv('sqlite://path/to/database.sqlite');
const keyv = new Keyv('postgresql://user:pass@localhost:5432/dbname');
const keyv = new Keyv('mysql://user:pass@localhost:3306/dbname');
// Handle DB connection errors
keyv.on('error', err => console.log('Connection Error', err));
await keyv.set('foo', 'expires in 1 second', 1000); // true
await keyv.set('foo', 'never expires'); // true
await keyv.get('foo'); // 'never expires'
await keyv.delete('foo'); // true
await keyv.clear(); // undefined
```
### Namespaces
You can namespace your Keyv instance to avoid key collisions and allow you to clear only a certain namespace while using the same database.
```js
const users = new Keyv('redis://user:pass@localhost:6379', { namespace: 'users' });
const cache = new Keyv('redis://user:pass@localhost:6379', { namespace: 'cache' });
await users.set('foo', 'users'); // true
await cache.set('foo', 'cache'); // true
await users.get('foo'); // 'users'
await cache.get('foo'); // 'cache'
await users.clear(); // undefined
await users.get('foo'); // undefined
await cache.get('foo'); // 'cache'
```
### Custom Serializers
Keyv uses [`json-buffer`](https://github.com/dominictarr/json-buffer) for data serialization to ensure consistency across different backends.
You can optionally provide your own serialization functions to support extra data types or to serialize to something other than JSON.
```js
const keyv = new Keyv({ serialize: JSON.stringify, deserialize: JSON.parse });
```
**Warning:** Using custom serializers means you lose any guarantee of data consistency. You should do extensive testing with your serialisation functions and chosen storage engine.
## Official Storage Adapters
The official storage adapters are covered by [over 150 integration tests](https://github.com/jaredwray/keyv/actions/workflows/build.yaml) to guarantee consistent behaviour. They are lightweight, efficient wrappers over the DB clients making use of indexes and native TTLs where available.
Database | Adapter | Native TTL | Status
---|---|---|---
Redis | [@keyv/redis](https://github.com/lukechilds/keyv-redis) | Yes | [](https://github.com/lukechilds/keyv-redis/actions/workflows/build.yaml) [](https://coveralls.io/github/lukechilds/keyv-redis?branch=master)
MongoDB | [@keyv/mongo](https://github.com/lukechilds/keyv-mongo) | Yes | [](https://github.com/lukechilds/keyv-mongo/actions/workflows/build.yaml) [](https://coveralls.io/github/lukechilds/keyv-mongo?branch=master)
SQLite | [@keyv/sqlite](https://github.com/lukechilds/keyv-sqlite) | No | [](https://github.com/lukechilds/keyv-sqlite/actions/workflows/build.yaml) [](https://coveralls.io/github/lukechilds/keyv-sqlite?branch=master)
PostgreSQL | [@keyv/postgres](https://github.com/lukechilds/keyv-postgres) | No | [](https://github.com/lukechilds/keyv-postgres/actions/workflows/build.yaml) [](https://coveralls.io/github/lukechilds/keyv-postgres?branch=master)
MySQL | [@keyv/mysql](https://github.com/lukechilds/keyv-mysql) | No | [](https://github.com/jaredwray/keyv-mysql/actions/workflows/build.yaml) [](https://coveralls.io/github/lukechilds/keyv-mysql?branch=master)
## Third-party Storage Adapters
You can also use third-party storage adapters or build your own. Keyv will wrap these storage adapters in TTL functionality and handle complex types internally.
```js
const Keyv = require('keyv');
const myAdapter = require('./my-storage-adapter');
const keyv = new Keyv({ store: myAdapter });
```
Any store that follows the [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) api will work.
```js
new Keyv({ store: new Map() });
```
For example, [`quick-lru`](https://github.com/sindresorhus/quick-lru) is a completely unrelated module that implements the Map API.
```js
const Keyv = require('keyv');
const QuickLRU = require('quick-lru');
const lru = new QuickLRU({ maxSize: 1000 });
const keyv = new Keyv({ store: lru });
```
The following are third-party storage adapters compatible with Keyv:
- [quick-lru](https://github.com/sindresorhus/quick-lru) - Simple "Least Recently Used" (LRU) cache
- [keyv-file](https://github.com/zaaack/keyv-file) - File system storage adapter for Keyv
- [keyv-dynamodb](https://www.npmjs.com/package/keyv-dynamodb) - DynamoDB storage adapter for Keyv
- [keyv-lru](https://www.npmjs.com/package/keyv-lru) - LRU storage adapter for Keyv
- [keyv-null](https://www.npmjs.com/package/keyv-null) - Null storage adapter for Keyv
- [keyv-firestore ](https://github.com/goto-bus-stop/keyv-firestore) – Firebase Cloud Firestore adapter for Keyv
- [keyv-mssql](https://github.com/pmorgan3/keyv-mssql) - Microsoft Sql Server adapter for Keyv
- [keyv-memcache](https://github.com/jaredwray/keyv-memcache) - Memcache storage adapter for Keyv
## Add Cache Support to your Module
Keyv is designed to be easily embedded into other modules to add cache support. The recommended pattern is to expose a `cache` option in your modules options which is passed through to Keyv. Caching will work in memory by default and users have the option to also install a Keyv storage adapter and pass in a connection string, or any other storage that implements the `Map` API.
You should also set a namespace for your module so you can safely call `.clear()` without clearing unrelated app data.
Inside your module:
```js
class AwesomeModule {
constructor(opts) {
this.cache = new Keyv({
uri: typeof opts.cache === 'string' && opts.cache,
store: typeof opts.cache !== 'string' && opts.cache,
namespace: 'awesome-module'
});
}
}
```
Now it can be consumed like this:
```js
const AwesomeModule = require('awesome-module');
// Caches stuff in memory by default
const awesomeModule = new AwesomeModule();
// After npm install --save keyv-redis
const awesomeModule = new AwesomeModule({ cache: 'redis://localhost' });
// Some third-party module that implements the Map API
const awesomeModule = new AwesomeModule({ cache: some3rdPartyStore });
```
## API
### new Keyv([uri], [options])
Returns a new Keyv instance.
The Keyv instance is also an `EventEmitter` that will emit an `'error'` event if the storage adapter connection fails.
### uri
Type: `String`
Default: `undefined`
The connection string URI.
Merged into the options object as options.uri.
### options
Type: `Object`
The options object is also passed through to the storage adapter. Check your storage adapter docs for any extra options.
#### options.namespace
Type: `String`
Default: `'keyv'`
Namespace for the current instance.
#### options.ttl
Type: `Number`
Default: `undefined`
Default TTL. Can be overridden by specififying a TTL on `.set()`.
#### options.serialize
Type: `Function`
Default: `JSONB.stringify`
A custom serialization function.
#### options.deserialize
Type: `Function`
Default: `JSONB.parse`
A custom deserialization function.
#### options.store
Type: `Storage adapter instance`
Default: `new Map()`
The storage adapter instance to be used by Keyv.
#### options.adapter
Type: `String`
Default: `undefined`
Specify an adapter to use. e.g `'redis'` or `'mongodb'`.
### Instance
Keys must always be strings. Values can be of any type.
#### .set(key, value, [ttl])
Set a value.
By default keys are persistent. You can set an expiry TTL in milliseconds.
Returns a promise which resolves to `true`.
#### .get(key, [options])
Returns a promise which resolves to the retrieved value.
##### options.raw
Type: `Boolean`
Default: `false`
If set to true the raw DB object Keyv stores internally will be returned instead of just the value.
This contains the TTL timestamp.
#### .delete(key)
Deletes an entry.
Returns a promise which resolves to `true` if the key existed, `false` if not.
#### .clear()
Delete all entries in the current namespace.
Returns a promise which is resolved when the entries have been cleared.
## License
MIT © Jared Wray & Luke Childs
keyv-4.0.4/media/ 0000775 0000000 0000000 00000000000 14137615212 0013556 5 ustar 00root root 0000000 0000000 keyv-4.0.4/media/logo.svg 0000664 0000000 0000000 00000004110 14137615212 0015233 0 ustar 00root root 0000000 0000000
keyv-4.0.4/package.json 0000664 0000000 0000000 00000002623 14137615212 0014770 0 ustar 00root root 0000000 0000000 {
"name": "keyv",
"version": "4.0.4",
"description": "Simple key-value storage with support for multiple backends",
"main": "src/index.js",
"scripts": {
"test": "xo && nyc ava test/keyv.js",
"test:full": "xo && nyc ava --serial",
"test:services:start": "docker-compose -f ./test/storage-adapters/services-compose.yaml up -d",
"test:services:stop": "docker-compose -f ./test/storage-adapters/services-compose.yaml down -v",
"coverage": "nyc report --reporter=text-lcov > coverage.lcov"
},
"xo": {
"extends": "xo-lukechilds",
"rules": {
"unicorn/prefer-module": 0
}
},
"repository": {
"type": "git",
"url": "git+https://github.com/jaredwray/keyv.git"
},
"keywords": [
"key",
"value",
"store",
"cache",
"ttl"
],
"author": "Jared Wray (http://jaredwray.com)",
"license": "MIT",
"bugs": {
"url": "https://github.com/jaredwray/keyv/issues"
},
"homepage": "https://github.com/jaredwray/keyv",
"dependencies": {
"json-buffer": "3.0.1"
},
"devDependencies": {
"@keyv/mongo": "*",
"@keyv/mysql": "*",
"@keyv/postgres": "*",
"@keyv/redis": "*",
"@keyv/sqlite": "*",
"@keyv/test-suite": "*",
"ava": "^3.15.0",
"codecov": "^3.8.3",
"eslint-config-xo-lukechilds": "^1.0.0",
"nyc": "^15.1.0",
"this": "^1.0.2",
"timekeeper": "^2.0.0",
"xo": "^0.46.3"
}
}
keyv-4.0.4/src/ 0000775 0000000 0000000 00000000000 14137615212 0013266 5 ustar 00root root 0000000 0000000 keyv-4.0.4/src/index.js 0000664 0000000 0000000 00000004645 14137615212 0014744 0 ustar 00root root 0000000 0000000 'use strict';
const EventEmitter = require('events');
const JSONB = require('json-buffer');
const loadStore = options => {
const adapters = {
redis: '@keyv/redis',
mongodb: '@keyv/mongo',
mongo: '@keyv/mongo',
sqlite: '@keyv/sqlite',
postgresql: '@keyv/postgres',
postgres: '@keyv/postgres',
mysql: '@keyv/mysql',
};
if (options.adapter || options.uri) {
const adapter = options.adapter || /^[^:]*/.exec(options.uri)[0];
return new (require(adapters[adapter]))(options);
}
return new Map();
};
class Keyv extends EventEmitter {
constructor(uri, options) {
super();
this.opts = Object.assign(
{
namespace: 'keyv',
serialize: JSONB.stringify,
deserialize: JSONB.parse,
},
(typeof uri === 'string') ? { uri } : uri,
options,
);
if (!this.opts.store) {
const adapterOptions = Object.assign({}, this.opts);
this.opts.store = loadStore(adapterOptions);
}
if (typeof this.opts.store.on === 'function') {
this.opts.store.on('error', error => this.emit('error', error));
}
this.opts.store.namespace = this.opts.namespace;
}
_getKeyPrefix(key) {
return `${this.opts.namespace}:${key}`;
}
get(key, options) {
const keyPrefixed = this._getKeyPrefix(key);
const { store } = this.opts;
return Promise.resolve()
.then(() => store.get(keyPrefixed))
.then(data => (typeof data === 'string') ? this.opts.deserialize(data) : data)
.then(data => {
if (data === undefined) {
return undefined;
}
if (typeof data.expires === 'number' && Date.now() > data.expires) {
this.delete(key);
return undefined;
}
return (options && options.raw) ? data : data.value;
});
}
set(key, value, ttl) {
const keyPrefixed = this._getKeyPrefix(key);
if (typeof ttl === 'undefined') {
ttl = this.opts.ttl;
}
if (ttl === 0) {
ttl = undefined;
}
const { store } = this.opts;
return Promise.resolve()
.then(() => {
const expires = (typeof ttl === 'number') ? (Date.now() + ttl) : null;
value = { value, expires };
return this.opts.serialize(value);
})
.then(value => store.set(keyPrefixed, value, ttl))
.then(() => true);
}
delete(key) {
const keyPrefixed = this._getKeyPrefix(key);
const { store } = this.opts;
return Promise.resolve()
.then(() => store.delete(keyPrefixed));
}
clear() {
const { store } = this.opts;
return Promise.resolve()
.then(() => store.clear());
}
}
module.exports = Keyv;
keyv-4.0.4/test/ 0000775 0000000 0000000 00000000000 14137615212 0013456 5 ustar 00root root 0000000 0000000 keyv-4.0.4/test/keyv.js 0000664 0000000 0000000 00000006755 14137615212 0015007 0 ustar 00root root 0000000 0000000 const test = require('ava');
const keyvTestSuite = require('@keyv/test-suite').default;
const Keyv = require('this');
const tk = require('timekeeper');
test.serial('Keyv is a class', t => {
t.is(typeof Keyv, 'function');
t.throws(() => Keyv()); // eslint-disable-line new-cap
t.notThrows(() => new Keyv());
});
test.serial('Keyv accepts storage adapters', async t => {
const store = new Map();
const keyv = new Keyv({ store });
t.is(store.size, 0);
await keyv.set('foo', 'bar');
t.is(await keyv.get('foo'), 'bar');
t.is(store.size, 1);
});
test.serial('Keyv passes tll info to stores', async t => {
t.plan(1);
const store = new Map();
const storeSet = store.set;
store.set = (key, value, ttl) => {
t.is(ttl, 100);
storeSet.call(store, key, value, ttl);
};
const keyv = new Keyv({ store });
await keyv.set('foo', 'bar', 100);
});
test.serial('Keyv respects default tll option', async t => {
const store = new Map();
const keyv = new Keyv({ store, ttl: 100 });
await keyv.set('foo', 'bar');
t.is(await keyv.get('foo'), 'bar');
tk.freeze(Date.now() + 150);
t.is(await keyv.get('foo'), undefined);
t.is(store.size, 0);
tk.reset();
});
test.serial('.set(key, val, ttl) overwrites default tll option', async t => {
const startTime = Date.now();
tk.freeze(startTime);
const store = new Map();
const keyv = new Keyv({ store, ttl: 200 });
await keyv.set('foo', 'bar');
await keyv.set('fizz', 'buzz', 100);
await keyv.set('ping', 'pong', 300);
t.is(await keyv.get('foo'), 'bar');
t.is(await keyv.get('fizz'), 'buzz');
t.is(await keyv.get('ping'), 'pong');
tk.freeze(startTime + 150);
t.is(await keyv.get('foo'), 'bar');
t.is(await keyv.get('fizz'), undefined);
t.is(await keyv.get('ping'), 'pong');
tk.freeze(startTime + 250);
t.is(await keyv.get('foo'), undefined);
t.is(await keyv.get('ping'), 'pong');
tk.freeze(startTime + 350);
t.is(await keyv.get('ping'), undefined);
tk.reset();
});
test.serial('.set(key, val, ttl) where ttl is "0" overwrites default tll option and sets key to never expire', async t => {
const startTime = Date.now();
tk.freeze(startTime);
const store = new Map();
const keyv = new Keyv({ store, ttl: 200 });
await keyv.set('foo', 'bar', 0);
t.is(await keyv.get('foo'), 'bar');
tk.freeze(startTime + 250);
t.is(await keyv.get('foo'), 'bar');
tk.reset();
});
test.serial('.get(key, {raw: true}) returns the raw object instead of the value', async t => {
const store = new Map();
const keyv = new Keyv({ store });
await keyv.set('foo', 'bar');
const value = await keyv.get('foo');
const rawObject = await keyv.get('foo', { raw: true });
t.is(value, 'bar');
t.is(rawObject.value, 'bar');
});
test.serial('Keyv uses custom serializer when provided instead of json-buffer', async t => {
t.plan(3);
const store = new Map();
const serialize = data => {
t.pass();
return JSON.stringify(data);
};
const deserialize = data => {
t.pass();
return JSON.parse(data);
};
const keyv = new Keyv({ store, serialize, deserialize });
await keyv.set('foo', 'bar');
t.is(await keyv.get('foo'), 'bar');
});
test.serial('Keyv supports async serializer/deserializer', async t => {
t.plan(3);
const store = new Map();
const serialize = async data => {
t.pass();
return JSON.stringify(data);
};
const deserialize = async data => {
t.pass();
return JSON.parse(data);
};
const keyv = new Keyv({ store, serialize, deserialize });
await keyv.set('foo', 'bar');
t.is(await keyv.get('foo'), 'bar');
});
const store = () => new Map();
keyvTestSuite(test, Keyv, store);
keyv-4.0.4/test/storage-adapters/ 0000775 0000000 0000000 00000000000 14137615212 0016723 5 ustar 00root root 0000000 0000000 keyv-4.0.4/test/storage-adapters/mongodb.js 0000664 0000000 0000000 00000000403 14137615212 0020703 0 ustar 00root root 0000000 0000000 const test = require('ava');
const keyvTestSuite = require('@keyv/test-suite').default;
const Keyv = require('this');
const KeyvMongo = require('@keyv/mongo');
const store = () => new KeyvMongo('mongodb://127.0.0.1:27017');
keyvTestSuite(test, Keyv, store);
keyv-4.0.4/test/storage-adapters/mysql.js 0000664 0000000 0000000 00000000630 14137615212 0020425 0 ustar 00root root 0000000 0000000 const test = require('ava');
const keyvTestSuite = require('@keyv/test-suite').default;
const { keyvOfficialTests } = require('@keyv/test-suite');
const Keyv = require('this');
const KeyvMysql = require('@keyv/mysql');
keyvOfficialTests(test, Keyv, 'mysql://root@localhost/keyv_test', 'mysql://foo');
const store = () => new KeyvMysql('mysql://root@localhost/keyv_test');
keyvTestSuite(test, Keyv, store);
keyv-4.0.4/test/storage-adapters/postgresql.js 0000664 0000000 0000000 00000000735 14137615212 0021471 0 ustar 00root root 0000000 0000000 const test = require('ava');
const keyvTestSuite = require('@keyv/test-suite').default;
const { keyvOfficialTests } = require('@keyv/test-suite');
const Keyv = require('this');
const KeyvPostgres = require('@keyv/postgres');
keyvOfficialTests(test, Keyv, 'postgresql://postgres:postgres@localhost:5432/keyv_test', 'postgresql://foo');
const store = () => new KeyvPostgres({ uri: 'postgresql://postgres:postgres@localhost:5432/keyv_test' });
keyvTestSuite(test, Keyv, store);
keyv-4.0.4/test/storage-adapters/redis.js 0000664 0000000 0000000 00000000572 14137615212 0020373 0 ustar 00root root 0000000 0000000 const test = require('ava');
const keyvTestSuite = require('@keyv/test-suite').default;
const { keyvOfficialTests } = require('@keyv/test-suite');
const Keyv = require('this');
const KeyvRedis = require('@keyv/redis');
keyvOfficialTests(test, Keyv, 'redis://localhost', 'redis://foo');
const store = () => new KeyvRedis('redis://localhost');
keyvTestSuite(test, Keyv, store);
keyv-4.0.4/test/storage-adapters/services-compose.yaml 0000664 0000000 0000000 00000001305 14137615212 0023074 0 ustar 00root root 0000000 0000000 version: '3.8'
services:
keyv_postgres:
image: postgres:latest
command: postgres -c 'max_connections=200'
environment:
POSTGRES_DB: keyv_test
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
ports:
- 5432:5432/tcp
keyv_mysql:
image: mysql:latest
command: --default-authentication-plugin=mysql_native_password
restart: always
ports:
- 3306:3306
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: 1
MYSQL_DATABASE: keyv_test
MYSQL_USER: mysql
keyv_redis:
image: redis:latest
environment:
REDIS_HOST: redis
ports:
- 6379:6379
keyv_mongo:
image: mongo
restart: always
ports:
- 27017:27017 keyv-4.0.4/test/storage-adapters/sqlite.js 0000664 0000000 0000000 00000000653 14137615212 0020566 0 ustar 00root root 0000000 0000000 const test = require('ava');
const keyvTestSuite = require('@keyv/test-suite').default;
const { keyvOfficialTests } = require('@keyv/test-suite');
const Keyv = require('this');
const KeyvSqlite = require('@keyv/sqlite');
keyvOfficialTests(test, Keyv, 'sqlite://test/testdb.sqlite', 'sqlite://non/existent/database.sqlite');
const store = () => new KeyvSqlite('sqlite://test/testdb.sqlite');
keyvTestSuite(test, Keyv, store);