npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tcpleveldb

v1.2.1

Published

a implementation of the leveldb with a tcp-server and client in node.js

Downloads

72

Readme

tcpleveldb

A node-js-tcp database environment with server and client on top of the leveldb.

You can run the server in a separate node-app as a standalone instance. Go to server. Then you can use the client in your node-app, web-app or another magic stuff to query the database. Go to client. You can find a web-gui to manage the database-servers here - tcpleveldb-panel.

Build Status

Web-GUI - https://github.com/yamigr/tcpleveldb-panel

Installing

npm install tcpleveldb --save

Server

var tcpleveldb = require('tcpleveldb')

var port = 2222
var host = 'localhost'
var user = ''
var password = ''

var srv = new tcpleveldb.Server(port, host, user, password)
srv.listen() 

//you can use some socket-events if needed
srv.on('end', function(msg){console.log(msg)})
srv.on('close', function(client){console.log(client)})
srv.on('error', function(err){console.log(err)})
srv.on('clientConnected', function(client){console.log(client)})
srv.on('clientMessage', function(msg){console.log(msg)})
srv.on('data', function(docs){console.log(docs)})

Client

  • You can define a new database at './db'. If needed, do something like './users' or './dashboards', ... .
  • While putting some data in the db and no key is set, auto-key is active. When the key containes '@key' (single or multiple-times), this substring will be replaced with a auto-key.
var tcpleveldb = require('tcpleveldb')

var port = 2222
var host = 'localhost'
var user = ''
var password = ''

var client = new tcpleveldb.Client(port, host, user, password)

// Define your own key which should be replaced by a unique id
client.key = '{mykey}'

// add some additional query data to handle it on the server-side-event 'clientMessage' or 'data'
client.addQuery = {topic : 'Hello'} 


//if key is empty it will create one like c10zlYDlf
client.put('./persons', {value : { name : 'Superman', city: 'Metropolis'}}, function(err, key){
    console.log(err, key)
    //Output: null, 'c10zlYDlf'

    client.get('./persons', key, function(err, doc){
        console.log(err, doc) 
        //Output: null, { key: 'c10zlYDlf', value: { name: 'Superman', city: 'Metropolis' } }
    })
})

client.put('./db', { key : 'PeterPan', value : { name : 'Peter Pan', city: 'Neverland'}}, function(err, key){
    console.log(err, key)

    client.get('./db', 'PeterPan', function(err, doc){
        console.log(err, doc) 
        //Output: null, { key: 'PeterPan', value: { name: 'Peter Pan', city: 'Neverland' } }
    })
})

client.get('./db', 'WhereIsMyKey', function(err, doc){
    console.log(err, doc) 
    // Output: NotFoundError: Key not found in database [WhereIsMyKey], { key: 'WhereIsMyKey' }
})



client.del('./db', 'Peter Pan', function(err, key){
    console.log(err, key) 
    // Output: null, Peter Pan
})


var batches = [
    { type: 'del', key: 'father' },
    { type: 'put', key: 'yamigr', value: 'https://github.com/yamigr' },
    { type: 'put', key: 'obj:1', value: { a : 123, b: 'abc', c :'Hello World!'} },
    { type: 'put', key: 'obj:2', value: { a : 1, b: 'xyz', c :'Hello World!'} }
]

client.batch('./db', batches, function(err, numberOfBatches){
    console.log(err, numberOfBatches) 
    // Output: null, 4
})


// ops : gte:'key', lte: 'key~', reverse, limit, lt, gt, start, end for timeseries...*/
// For api options details see https://www.npmjs.com/package/leveldb. Thx :)
// For gte and lte query see https://medium.com/@kevinsimper/how-to-get-range-of-keys-in-leveldb-and-how-gt-and-lt-works-29a8f1e11782 Thx :)
client.stream('./db', { /* ops */}, function(err, docs){
    console.log(err, docs) 
    // Output: null, [ { key: 'yamigr', value: 'https://github.com/yamigr' }, ...]
})
client.stream('./db', function(err, docs){
    console.log(err, docs) 
    // without options you can stream the whole database
})

// stream all keys
client.keys('./db', { /* ops */}, function(err, docs){
    console.log(err, docs) 
    // Output: null, [ key1, ...]
})

// stream all keys
client.values('./db', { /* ops */}, function(err, docs){
    console.log(err, docs) 
    // Output: null, [ value1, ...]
})

client.count('./db', {gte : 'obj:', lte : 'obj:~' /*ops*/}, function(err, numb){
    console.log(err, numb) 
    // Output: null, 2
})
client.count('./db', function(err, docs){
    console.log(err, docs) 
    // without options you can count the whole database
})

/* mongodb like array-filtering. a huge thx to davidtpate, https://www.npmjs.com/package/bloc 
   the array to filter looks like [ { key : '', value : '' or object }, ....].
   a single entry with object as value looks like {key : 'test', value: { test : 'mongooselike', obj : { nested : 'filter'}}}
   the nested filter looks like { 'value.obj.nested' : { $in : ['filter'] }}
   in the example bellow, the value is a string
*/
client.filter('./db', { value : { $in : ['Special key', 'Whoooooooop']}}, function(err, docs){
    console.log(err, docs) 
    // Output: null [ { key: '-Gj_-CweyG', value: 'Special key' },
    //                { key: 'test', value: 'Whoooooooop' } ]
})


client.update('./db', { key : 'obj:1', value: {b : 'Whooooooooop'}}, function(err, key){
    console.log(err, key) 
    // Output: null, obj:1

    client.get('./db', key, function(err, doc){
        console.log(err, doc) 
        // Output: null, { key: 'obj:1', value: { a: 123, b: 'Whooooooooop', c: 'Hello World!' } }
    })
})

// use the query method the use all query-options in one method
client.query('./db', 'put', { key : 'querytest', value : 'hello'}, function(docs){
    if(docs.err){
        // handle err
    }
    else{
        client.query('./db', 'get', { key : 'querytest'}, function(docs){
                // docs { err : null, data : {key: 'querytest', value: 'hello'}}
        })
    }
})

client.on('error', function(err){console.log(err)})
client.on('connect', function(status){console.log(status)})
client.on('close', function(status){console.log(status)})
client.on('data', function(err, data){console.log(data)})

Authors

  • Yannick Grund - Initial work - yamigr

License

This project is licensed under the MIT License - see the LICENSE.md file for details