1.7.85 • Published 12 months ago

generalised-datastore v1.7.85

Weekly downloads
-
License
ISC
Repository
github
Last release
12 months ago

Generalised Datastore

Installation

npm install generalised-datastore --save

Usage

import GDS from "generalised-datastore";

// Initiate Datastore object
let gds = new GDS("ds1").sync();
// Create folders
let Folder1 = gds.folder("folder1");
let Folder2 = gds.folder("folder2");

/* Basic CRUD Queries */

// Write Queries
Folder1.write({ info: "info1" });
Folder1.write_several(new Array({ info: "info1" }, { info: "info2" }));

// Read Queries
Folder1.read(query);
Folder1.readone(query); // limit 1

// Update Queries
Folder1.update(read_query, update_query); // limit 1
Folder1.update_several(read_query, update_query);

// Remove Queries
Folder1.remove(query); // limit 1
Folder1.remove_several(query);

// Replace Queries
Folder1.replace(read_query, replacement); // limit 1

Features

  • Multi-depth (Read, Write) joins.

Folder1.write({
  info: "info1",
  info2: {
    _id: "folder2~rand~time", // || "folder2"
    info: "info2",
  },
});

This stores: folder1 -> {_id: 'folder1~rand~time', info: 'info1', info2: 'folder2~rand~time'} folder2 -> {_id: 'folder2~rand~time', info: 'info2'}

  • Subfolder

let Posts_likes = gds.folder("postlikes", "post");
Posts_likes.write({
  post: "posts~1~time",
  liker: "user~xyz~time",
});
Posts_likes.write({
  post: "posts~2~time",
  liker: "user~abc~time",
});
Posts_likes.write({
  post: "posts~1~time",
  liker: "user~abc~time",
});

This stores: postslikes -> posts~1~time -> {_id: 'postslikes~rand~time', post: 'posts~1~time', liker: 'user~xyz~time'}\n {_id: 'postslikes~rand1~time', post: 'posts~1~time', liker: 'user~abc~time'} postslikes -> posts~2~time -> {_id: 'postslikes~rand~time', post: 'posts~2~time', liker: 'user~xyz~time'}

  • Dynamic Query extension

Folder.add_query('has', (query)=>{
  return !!Folder.readone(query);
});

Folder.has('_id~xyz~123'); // returns bool
  • Paging

  • Event Handling

Properties and Methods

GDS

Type class

Properties constructor parameters datastore_name base_pathoptional

Method NameArgumentArgument TypeMeaning
folderfolder_namestringFolder's name.
subfolderstringstring[]Folder entries property that would serve as subfolder group.
joinsstringstring[]Folder entries property that's joined from other folders.
syncsync_handlerfunctionfunction[]Function(s) that would be called on sync of the datastore.

Folder

let Folder = gds.folder("folder_name");
Method NameArgumentArgument TypeMeaning
add_queryquerystringQuery name.
handlerfunctionHandler that would be called on folderquery.
remove_queryquerystringRemoves query from folder crud.
readqueryobject_id stringRead filter
optionsobject
readoneSame as read, only limit = 1.
removequeryobject_id stringRemove filter.
optionsobject
remove_severalSame as remove, only limit is as many as match.
replaceSyntactic method to perform remove and write operations in one call.
replace_queryobject_id stringQuery to match folder entry to be replaced i.e removed
replacementobjectData to replace removed folder entry
optionsobject
writedataobjectData to be written to folder.
optionsobject
write_severalSame as write, only it accepts a data array and reiteratively write to folder.
updatequeryobject_id stringQuery to filter folder entry for update
update_queryobjectUpdate to be made on folder entry.
optionsobject
update_severalSame as update, only it update as many query-match as found in folder.

Exposing the Event Listener Decorator

Method NameArgumentArgument TypeMeaning
add_folder_listenerlistenerfunctionFunction(s) that would be called on folder creation.
add_listenereventstringEvent name that would be fired on emit.
listenerfunctionFunction that would be appended to event, for firing on emit.
add_query_listenerlistenerfunctionFunction(s) that would be called on (any) query call.
add_read_listenerlistenerfunctionFunction(s) that would be called on read queries.
add_remove_listenerlistenerfunctionFunction(s) that would be called on remove queries.
add_write_listenerlistenerfunctionFunction(s) that would be called on write queries.
add_update_listenerlistenerfunctionFunction(s) that would be called on update queries.
emiteventstringEvent that is being emitted.
payloadanyArgument provided to listeners being called on event. A second argument (this) is provided to listeners being the object being listened on.
callbackfunctionA function that is called after all listeners has been called. The callback is given an argment, which is an array of the return values of the called listeners.
on_listener_addedlistenerfunctionFunction to be appended to listeners, called on a new listener added to any event.
remove"Boolean(truthy)"If provided, removes listener instead, as oppose to append.
on_listener_removedlistenerfunctionFunction to be appended to listeners, called on listener removed from any event.
remove"Boolean(truthy)"If provided, removes listener instead, as oppose to append.
on_read_filelistenerfunctionFunction appended to listeners array, to be called on file read as saved to disk, before any further parsing. If return truthy, return value is assigned as read file and recursively passed sequentially to other listeners for parsing if any.
removeBoolean(truthy)If provided, removes listener instead, as oppose to append.
on_user_query_listenerquerystringUser query to emit listeners on call.
listenerfunctionFunction to be appended to user query listeners for call on emit.
removeBoolean(truthy)If provided, removes listener instead, as oppose to append.
on_write_filelistenerfunctionFunction appended to listeners array, to be called on file to be saved to disk, with no further parsing. If return truthy, return value is assigned as value to be written to file, and recursively passed sequentially to other listeners for parsing if any.
removeBoolean(truthy)If provided, removes listener instead, as oppose to append.
remove_eventeventstringEvent to be removed from events object, clearing all event's listeners.
remove_folder_listenerlistenerfunctionBoolean(true)Remove single listener if provided function, else if boolean-true, removes all folder listeners.
remove_listenereventstringEvent name whose listener is to be removed.
listenerfunctionListener to be remove from event name provided.
remove_query_listenerlistenerfunctionBoolean(true)Remove single listener if provided function, else if boolean-true, removes all query listeners
remove_read_listenerlistenerfunctionBoolean(true)Remove single listener if provided function, else if boolean-true, removes all read listeners
remove_replace_listenerlistenerfunctionBoolean(true)Remove single listener if provided function, else if boolean-true, removes all replace listeners
remove_remove_listenerlistenerfunctionBoolean(true)Remove single listener if provided function, else if boolean-true, removes all remove listeners
remove_write_listenerlistenerfunctionBoolean(true)Remove single listener if provided function, else if boolean-true, removes all write listeners
remove_update_listenerlistenerfunctionBoolean(true)Remove single listener if provided function, else if boolean-true, removes all update listeners

Listeners are called with this object passed as first argument, the query response as second argument and query metadata as third argument.

See the package source for more details.

1.7.84

12 months ago

1.7.85

12 months ago

1.7.78

1 year ago

1.7.79

1 year ago

1.7.80

1 year ago

1.7.81

1 year ago

1.7.82

1 year ago

1.7.83

1 year ago

1.7.75

1 year ago

1.7.76

1 year ago

1.7.70

1 year ago

1.7.71

1 year ago

1.7.72

1 year ago

1.7.73

1 year ago

1.7.74

1 year ago

1.7.66

2 years ago

1.7.0

2 years ago

1.5.2

2 years ago

1.6.0

2 years ago

1.5.1

2 years ago

1.7.60

2 years ago

1.7.61

2 years ago

1.7.62

2 years ago

1.7.51

2 years ago

1.7.63

2 years ago

1.7.65

2 years ago

1.6.9

2 years ago

1.7.5

2 years ago

1.6.5

2 years ago

1.5.0

2 years ago

1.0.0

2 years ago