1657097122
level-subkey
The level-subkey is modified from level-sublevel.
The level-subkey use the path to separate sections of levelup, with hooks! these sublevels are called dynamic subkey.
This module allows you to create a hierarchy data store with levelup-sync database, kinda like tables in an sql database, but hierarchical, evented, and ranged, for real-time changing data.
The key is always string only unless it's an index.
Unstable: Expect patches and features, possible api changes.
This module is working well, but may change in the future as its use is further explored.
The internal key path storage like file path, but the path separator can be customize.
var precodec = require('level-subkey/lib/codec')
precodec.SUBKEY_SEPS = ["/|-", "#.+"] //the first char is the default subkey separator, others are customize separator.
subkey.put("some", "value", {separator: '|'})
//list all key/value on separator "|"
subkey.createReadStream({separator: '.'})
//it will return all prefixed "|" keys: {key: "|abc", value:....}
var stuff = db.subkey('stuff')
var animal = stuff.subkey('animal')
var plant = stuff.subkey('plant')
animal.put("pig", value, function () {})
// stored raw key is : "/stuff/animal#pig"
// decoded key is: "/stuff/animal/pig"
animal.put("../plant/cucumber", value, function (err) {})
// stored raw key is : "/stuff/plant#cucumber"
// decoded key is: "/stuff/animal/cucumber"
db.put("/stuff/animal/pig/.mouth", value, function(err){})
// stored raw key is : "/stuff/animal/pig*mouth"
// decoded key is: "/stuff/animal/pig/.mouth"
db.put("/stuff/animal/pig/.ear", value, function(err){})
// stored raw key is : "/stuff/animal/pig*ear"
// decoded key is: "/stuff/animal/pig/.ear"
db.put("/stuff/animal/pig/.ear/.type", value, function(err){})
// stored raw key is : "/stuff/animal/pig/.ear*type"
// decoded key is: "/stuff/animal/pig/.ear/.type"
Create(or get from a global cache) a new Subkey instance, and load the value if this key is exists on the database
arguments
return
The usages:
arguments
return
Get the subkey itself whether is an alias or not.
arguments
return
Create an alias for the keyPath:
Create an alias for itself:
arguments
return
create a read stream to visit the child subkeys of this subkey.
arguments
'path'
(string|Subkey Object): can be relative or absolute key path or another subkey object to search'next'
: the raw key data to ensure the readStream/pathStream return keys is greater than the key. See 'last'
event.'separator'
(char)'filter'
(function): to filter data in the stream'bounded'
(boolean, default: true
): whether limit the boundary to this subkey only.'separatorRaw'
(boolean, default: false
): do not convert the separator, use the separator directly if true.'keys'
(boolean, default: true
): whether the 'data'
event should contain keys. If set to true
and 'values'
set to false
then 'data'
events will simply be keys, rather than objects with a 'key'
property. Used internally by the createKeyStream()
method.'values'
(boolean, default: true
): whether the 'data'
event should contain values. If set to true
and 'keys'
set to false
then 'data'
events will simply be values, rather than objects with a 'value'
property. Used internally by the createValueStream()
method.'limit'
(number, default: -1
): limit the number of results collected by this stream. This number represents a maximum number of results and may not be reached if you get to the end of the data first. A value of -1
means there is no limit. When reverse=true
the highest keys will be returned instead of the lowest keys.'fillCache'
(boolean, default: false
): wheather LevelDB's LRU-cache should be filled with data read.return
the standard 'data'
, 'error'
, 'end'
and 'close'
events are emitted. the 'last'
event will be emitted when the last data arrived, the argument is the last raw key(no decoded). if no more data the last key is undefined
.
filter usage:
db.createReadStream({filter: function(key, value){
if (/^hit/.test(key))
return db.FILTER_INCLUDED
else key == 'endStream'
return db.FILTER_STOPPED
else
return db.FILTER_EXCLUDED
}})
.on('data', function (data) {
console.log(data.key, '=', data.value)
})
.on('error', function (err) {
console.log('Oh my!', err)
})
.on('close', function () {
console.log('Stream closed')
})
.on('end', function () {
console.log('Stream closed')
})
next and last usage for paged data demo:
var callbackStream = require('callback-stream')
var lastKey = null;
function nextPage(db, aLastKey, aPageSize, cb) {
var stream = db.readStream({next: aLastKey, limit: aPageSize})
stream.on('last', function(aLastKey){
lastKey = aLastKey;
});
stream.pipe(callbackStream(function(err, data){
cb(data, lastKey)
}))
}
var pageNo = 1;
dataCallback = function(data, lastKey) {
console.log("page:", pageNo);
console.log(data);
++pageNo;
if (lastKey) {
nextPage(db, lastKey, 10, dataCallback);
}
else
console.log("no more data");
}
nextPage(db, lastKey, 10, dataCallback);
var LevelUp = require('levelup')
var Subkey = require('level-subkey')
var db = Subkey(LevelUp('/tmp/sublevel-example'))
var stuff = db.subkey('stuff')
//it is same as stuff = db.sublevel('stuff') but db.sublevel is deprecated.
//put a key into the main levelup
db.put(key, value, function () {})
//put a key into the sub-section!
stuff.put(key2, value, function () {})
Sublevel prefixes each subsection so that it will not collide with the outer db when saving or reading!
var LevelUp = require('levelup')
var Subkey = require('level-subkey')
var db = Subkey(LevelUp('/tmp/sublevel-example'))
//old sublevel usage:
var stuff = db.subkey('stuff') //or stuff = db.path('stuff')
var animal = stuff.subkey('animal') //or animal = stuff.path('animal')
var plant = stuff.subkey('plant')
//put a key into animal!
animal.put("pig", value, function () {})
//new dynamic hierarchy data storage usage:
animal.put("../plant/cucumber", value, function (err) {})
db.put("/stuff/animal/pig", value, function(err){})
db.get("/stuff/animal/pig", function(err, value){})
//put pig's attribute as key/value
db.put("/stuff/animal/pig/.mouth", value, function(err){})
db.put("/stuff/animal/pig/.ear", value, function(err){})
//list all pig's attributes
db.createReadStream({path: "/stuff/animal/pig", separator="."})
//return: {".mouth":value, ".ear":value}
//list all pig's path(excludes the subkeys)
//it will search from "/stuff/\x00" to "/stuff/\uffff"
db.createPathStream({path: "/stuff"}) //= db.createReadStream({separator:'/', separatorRaw: true, start:'0'})
//return:{ 'animal/pig': value, 'animal/pig.ear': value, 'animal/pig.mouth': value, 'plant/cucumber': value}
//list all keys in "/stuff/animal"
db.createReadStream({path: "/stuff/animal"})
//list all keys in "/stuff/plant"
animal.createReadStream({start: "../plant"})
//write by stream
var wsAnimal = animal.createWriteStream()
wsAnimal.on('err', function(err){throw err})
wsAnimal.on('close', function(){})
wsAnimal.write({key: "cow", value:value})
wsAnimal.write({key: "/stuff/animal/cow", value:value})
wsAnimal.write({key: "../plant/tomato", value:value})
wsAnimal.end()
//crazy usage:
//the path will always be absolute key path.
//Warning: setPath will be broken the subkeys cache on nut!!
// if setPath it will remove itself from cache.
animal.setPath("/stuff/plant")
animal.setPath(plant)
//now the "animal" is plant in fact.
animal.get("cucumber", function(err, value){})
Hooks are specially built into Sublevel so that you can do all sorts of clever stuff, like generating views or logs when records are inserted!
Records added via hooks will be atomically inserted with the triggering change.
//you should be careful of using the add() function
//maybe endless loop in it. u can disable the trigger
add({
key:...,
value:...,
type:'put' or 'del',
triggerBefore: false, //defalut is true. whether trigger this key on pre hook.
triggerAfter: false //defalut is true. whether trigger this key on post hook.
})
add(false): abondon this operation(remove it from the batch).
Whenever a record is inserted, save an index to it by the time it was inserted.
var sub = db.subkey('SEQ')
db.pre(function (ch, add) {
add({
key: ''+Date.now(),
value: ch.key,
type: 'put',
// NOTE: pass the destination db to add the value to that subsection!
path: sub
})
})
db.put('key', 'VALUE', function (err) {
// read all the records inserted by the hook!
sub.createReadStream().on('data', console.log)
})
Notice that the parent
property to add()
is set to sub
, which tells the hook to save the new record in the sub
section.
var sub = db.subkey('SEQ')
//Hooks range
db.pre({gte:"", lte:"", path:""}, function (ch, add) {
add({
key: ''+Date.now(),
value: ch.key,
type: 'put',
// NOTE: pass the destination db to add the value to that subsection!
path: sub
})
})
//hooks a key, and the key can be relative or absolute key path and minimatch supports.
db.pre("a*", function (ch, add) {
//NOTE: add(false) means do not put this key into storage.
add({
key: ''+Date.now(),
value: ch.key,
type: 'put',
// NOTE: pass the destination db to add the value to that subsection!
path: sub
})
})
In sublevel
batches also support a prefix: subdb
property, if set, this row will be inserted into that database section, instead of the current section, similar to the pre
hook above.
var sub1 = db.subkey('SUB_1')
var sub2 = db.subkey('SUB_2')
sub2.batch([
{key: 'key', value: 'Value', type: 'put'},
{key: 'key', value: 'Value', type: 'put', path: sub2},
{key: '../SUB_1/key', value: 'Value', type: 'put', path: sub2},
], function (err) {...})
Author: Snowyu
Source Code: https://github.com/snowyu/level-subkey
License: MIT license
1625133780
The pandemic has brought a period of transformation across businesses globally, pushing data and analytics to the forefront of decision making. Starting from enabling advanced data-driven operations to creating intelligent workflows, enterprise leaders have been looking to transform every part of their organisation.
SingleStore is one of the leading companies in the world, offering a unified database to facilitate fast analytics for organisations looking to embrace diverse data and accelerate their innovations. It provides an SQL platform to help companies aggregate, manage, and use the vast trove of data distributed across silos in multiple clouds and on-premise environments.
**Your expertise needed! **Fill up our quick Survey
#featured #data analytics #data warehouse augmentation #database #database management #fast analytics #memsql #modern database #modernising data platforms #one stop shop for data #singlestore #singlestore data analytics #singlestore database #singlestore one stop shop for data #singlestore unified database #sql #sql database
1620466520
If you accumulate data on which you base your decision-making as an organization, you should probably think about your data architecture and possible best practices.
If you accumulate data on which you base your decision-making as an organization, you most probably need to think about your data architecture and consider possible best practices. Gaining a competitive edge, remaining customer-centric to the greatest extent possible, and streamlining processes to get on-the-button outcomes can all be traced back to an organization’s capacity to build a future-ready data architecture.
In what follows, we offer a short overview of the overarching capabilities of data architecture. These include user-centricity, elasticity, robustness, and the capacity to ensure the seamless flow of data at all times. Added to these are automation enablement, plus security and data governance considerations. These points from our checklist for what we perceive to be an anticipatory analytics ecosystem.
#big data #data science #big data analytics #data analysis #data architecture #data transformation #data platform #data strategy #cloud data platform #data acquisition
1618053720
Databases store data in a structured form. The structure makes it possible to find and edit data. With their structured structure, databases are used for data management, data storage, data evaluation, and targeted processing of data.
In this sense, data is all information that is to be saved and later reused in various contexts. These can be date and time values, texts, addresses, numbers, but also pictures. The data should be able to be evaluated and processed later.
The amount of data the database could store is limited, so enterprise companies tend to use data warehouses, which are versions for huge streams of data.
#data-warehouse #data-lake #cloud-data-warehouse #what-is-aws-data-lake #data-science #data-analytics #database #big-data #web-monetization
1618664160
Reading about the death of the relational database seems like a regular occurrence. However, here we are in 2021, and the relational data store is going strong. If we look at the DB-Engines Ranking website, six of the top 10, including the top four spots, are all relational data stores. Evidently, structured, or relational, data storage is here to stay. Yet four of the top spots are held by non-relational engines. Could that mean that relational data storage is really dying?
The core of this question is not really which kind of data store is better between a relational, normalized structure or a non-relational, denormalized storage mechanism. No, the real core question is: What kind of data store should your organization be using in 2021?
The shortest possible way I can answer this question is as follows:
All of them.
The fact is, you’re much better off not trying to answer your data needs with one, single methodology. Let’s discuss why.
#nosql #sql #data storage #relational database #data consistency #relational data #structured data #non-relational database #data stores #database choice
1620629020
The opportunities big data offers also come with very real challenges that many organizations are facing today. Often, it’s finding the most cost-effective, scalable way to store and process boundless volumes of data in multiple formats that come from a growing number of sources. Then organizations need the analytical capabilities and flexibility to turn this data into insights that can meet their specific business objectives.
This Refcard dives into how a data lake helps tackle these challenges at both ends — from its enhanced architecture that’s designed for efficient data ingestion, storage, and management to its advanced analytics functionality and performance flexibility. You’ll also explore key benefits and common use cases.
As technology continues to evolve with new data sources, such as IoT sensors and social media churning out large volumes of data, there has never been a better time to discuss the possibilities and challenges of managing such data for varying analytical insights. In this Refcard, we dig deep into how data lakes solve the problem of storing and processing enormous amounts of data. While doing so, we also explore the benefits of data lakes, their use cases, and how they differ from data warehouses (DWHs).
This is a preview of the Getting Started With Data Lakes Refcard. To read the entire Refcard, please download the PDF from the link above.
#big data #data analytics #data analysis #business analytics #data warehouse #data storage #data lake #data lake architecture #data lake governance #data lake management