Skip to content

Commit

Permalink
fix: changed all adapter apis to support (uri, option)
Browse files Browse the repository at this point in the history
Changed APIs ( major bump ) for mysql, sqlite, postgres, added a disclaimer in mongo

Signed-off-by: Jytesh <44925963+Jytesh@users.noreply.github.com>
  • Loading branch information
Jytesh committed Mar 8, 2022
1 parent ff0274a commit f78a5dd
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
5 changes: 5 additions & 0 deletions packages/mongo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ const keyv = new Keyv({
})
```

```
NOTE:
The mongo adapter deviates from the adapter in terms of uri options, you need to specify url instead of uri when passing the DB URL in the options
```

## License

**@keyvhq/mongo** © [Luke Childs](https://lukechilds.co), Released under the [MIT](https://github.com/microlinkhq/keyv/blob/master/LICENSE.md) License.<br/>
Expand Down
11 changes: 8 additions & 3 deletions packages/mysql/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ const KeyvSql = require('@keyvhq/sql')
const mysql = require('mysql2/promise')

class KeyvMysql extends KeyvSql {
constructor (options) {
if (typeof options === 'string') {
options = { uri: options }
constructor (uri, options) {
uri = uri || {}
if (typeof uri === 'string') {
uri = { uri }
}

if (uri.uri) {
uri = Object.assign({ uri: uri.uri }, uri)
}

options = Object.assign(
Expand Down
11 changes: 10 additions & 1 deletion packages/postgres/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,21 @@ const KeyvSql = require('@keyvhq/sql')
const Pool = require('pg').Pool

class KeyvPostgres extends KeyvSql {
constructor (options) {
constructor (uri, options) {
uri = uri || {}
if (typeof uri === 'string') {
uri = { uri }
}

if (uri.uri) {
uri = Object.assign({ uri: uri.uri }, uri)
}
options = Object.assign(
{
dialect: 'postgres',
uri: 'postgresql://localhost:5432'
},
uri,
options
)

Expand Down
11 changes: 10 additions & 1 deletion packages/sqlite/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,21 @@ const sqlite3 = require('sqlite3')
const pify = require('pify')

class KeyvSqlite extends KeyvSql {
constructor (options) {
constructor (uri, options) {
uri = uri || {}
if (typeof uri === 'string') {
uri = { uri }
}

if (uri.uri) {
uri = Object.assign({ uri: uri.uri }, uri)
}
options = Object.assign(
{
dialect: 'sqlite',
uri: 'sqlite://:memory:'
},
uri,
options
)
options.db = options.uri.replace(/^sqlite:\/\//, '')
Expand Down

0 comments on commit f78a5dd

Please sign in to comment.