Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

knex-log

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

knex-log - npm Package Compare versions

Comparing version 2.0.0 to 2.1.0

20

index.js

@@ -5,6 +5,8 @@ const stream = require('stream');

module.exports = (knex, config) => {
const columnName = config.columnName || 'value';
async function open () {
return knex.schema.createTableIfNotExists(config.tableName, function (table) {
table.increments();
table.jsonb('value');
table.jsonb(columnName);
table.timestamps(true, true);

@@ -21,4 +23,6 @@ }).then(() => {

async function append (payload) {
const data = {};
data[columnName] = JSON.stringify(payload);
return knex(config.tableName)
.insert({ value: JSON.stringify(payload) })
.insert(data)
.returning('id')

@@ -37,6 +41,6 @@ .then((inserted) => {

async function get (offset) {
return knex(config.tableName).first('id', 'value')
return knex(config.tableName).first('id', columnName)
.where({ id: offset.id })
.then((obj) => {
return JSON.parse(obj.value);
return JSON.parse(obj[columnName]);
});

@@ -48,4 +52,6 @@ }

ws._write = (payload, enc, cb) => {
const data = {};
data[columnName] = JSON.stringify(payload);
return knex(config.tableName)
.insert({ value: JSON.stringify(payload) })
.insert(data)
.then(() => cb())

@@ -58,7 +64,7 @@ .catch(cb);

function createReadStream (opts = {}) {
return knex(config.tableName).select('id', 'value', 'created_at')
return knex(config.tableName).select('id', columnName, 'created_at')
.where('id', '>=', (opts.offset && opts.offset.id) || 0)
.stream()
.pipe(streamMap({ objectMode: true }, (obj) => {
return { offset: { id: obj.id, timestamp: obj.created_at }, value: JSON.parse(obj.value) };
return { offset: { id: obj.id, timestamp: obj.created_at }, value: JSON.parse(obj[columnName]) };
}));

@@ -65,0 +71,0 @@ }

{
"name": "knex-log",
"description": "Implementation of a log using knex.",
"version": "2.0.0",
"version": "2.1.0",
"author": "Tim Allen <tim@noblesamurai.com>",

@@ -6,0 +6,0 @@ "license": "BSD",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc