Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle data stored as jsonb #35

Merged
merged 1 commit into from May 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions README.md
Expand Up @@ -25,9 +25,8 @@ plugins:
prefix: ds_ # table prefix defaults to empty string, so no prefix
max: 10 #concurrent connections
idleTimeoutMillis: 30000 #timeout after which connection will be cut
writeInterval: 200 #amout of milliseconds during which writes will be
writeInterval: 200 #amount of milliseconds during which writes will be buffered
useJsonb: false #store values as searchable binary JSON (slower)
buffered
notifications:
CREATE_TABLE: false #Get notified when tables are created
DESTROY_TABLE: false #Get notified when tables are dropped
Expand Down
7 changes: 5 additions & 2 deletions src/connector.ts
Expand Up @@ -228,8 +228,11 @@ export class Connector extends DeepstreamPlugin implements DeepstreamStorage {
callback(null, -1, null)
}
else {
const { version, val } = result.rows[0]
callback(null, version, JSON.parse(val))
let { version, val } = result.rows[0]
if (typeof val === 'string') {
val = JSON.parse(val)
}
callback(null, version, val)
}
}, [], true)
}
Expand Down
17 changes: 9 additions & 8 deletions test/cache-connector.spec.ts
Expand Up @@ -6,12 +6,13 @@ import { EventEmitter } from 'events'
import { DeepstreamServices } from '@deepstream/types'

const settings = {
schema: 'test',
schema: '__dstest',
user: process.env.POSTGRES_USER || 'postgres',
database: process.env.POSTGRES_DB || 'postgres',
password: process.env.POSTGRES_PASSWORD || 'mysecretpassword',
host: process.env.PGHOST || 'localhost',
port: parseInt(process.env.PGPORT!, 10) || 5432,
useJsonb: true, // store values as searchable binary JSON (slower)
max: 10,
idleTimeoutMillis: 30000,
notifications: {
Expand Down Expand Up @@ -77,11 +78,11 @@ describe('connector', () => {
})

it('creates a schema', async () => {
dbConnector.createSchema('some-schema')
dbConnector.createSchema(settings.schema)
})

it('deletes a schema', async () => {
await dbConnector.destroySchema('some-schema')
await dbConnector.destroySchema(settings.schema)
})

it('destroys the connector', async () => {
Expand Down Expand Up @@ -194,11 +195,11 @@ describe('connector', () => {
})

it('deletes the possible schema', async () => {
await dbConnector.destroySchema('test')
await dbConnector.destroySchema(settings.schema)
})

it('creates the possible schema', async () => {
await dbConnector.createSchema('test')
await dbConnector.createSchema(settings.schema)
})

it('subscribes to notifications', async () => {
Expand Down Expand Up @@ -463,16 +464,16 @@ describe('connector', () => {
})

it('creates a database', async () => {
await dbConnector.createSchema('ds')
await dbConnector.createSchema(settings.schema)
})

it('destroys a database', async () => {
await dbConnector.destroySchema('ds')
await dbConnector.destroySchema(settings.schema)
})

it('fails when trying to delete a non existing database', async () => {
try {
await dbConnector.destroySchema('ds')
await dbConnector.destroySchema(settings.schema)
throw new Error('An error should have been thrown')
} catch (e) {
}
Expand Down