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

Data Persistence #146

Open
acefxlabs opened this issue Sep 12, 2017 · 5 comments
Open

Data Persistence #146

acefxlabs opened this issue Sep 12, 2017 · 5 comments
Assignees

Comments

@acefxlabs
Copy link

Is there a way to make TaffyDB data persistent so it can stay even onreload of page

@mmikowski
Copy link
Collaborator

mmikowski commented Sep 15, 2017

You can serialize and store Taffy data using JSON and localStorage as shown below:

var db_fn, record_list, json_str;
db_fn       = TAFFY( [ { name : 'fred' } ] );
record_list = db_fn().get();
json_str    =  JSON.stringify( record_list );
localStorage.setItem( 'my_taffy_key', json_str ) );

And then to retrieve:

var json_str, record_list, db_fn;
json_str    = localStorage.getItem( 'my_taffy_key' );
record_list = JSON.parse( json_str );
db_fn       = TAFFY( record_list );

Please confirm if this works for you. I propose to add this to the README and then close.

@mmikowski mmikowski self-assigned this Sep 18, 2017
@mmikowski
Copy link
Collaborator

@acefxlabs is this answer working for you? Please confirm and we can resolve the issue.

@pmrivas
Copy link

pmrivas commented Oct 18, 2017

Hi!.. i'm not acefxlabs... but it worked for me!..
i'm using 3000 rows and works like a charm! with 4 tables..

@tremendus
Copy link

Related to this, I need to write an adapter to write persistent data to filesystem. Are there any examples of this type of persistence I can use as a model or am I starting from scratch here? Any thoughts on whether this is practical ... and wise? ;)

Use case: I am building an embedded server that must handle a modest number of records with persistence but is light on resources (ie. not enough for sqlite).

I plan to persist records as JSON (actually YAML) files the filesystem. So I need to initially populate the records into a taffy db on server start up, and then dump records to YAML @filesystem on store().

I also need to store one-to-many child data records under the parent (as streams) because there may be thousands of records in some cases.

Any hints, tips, thoughts, gotchas?

@brittonk
Copy link

You can serialize and store Taffy data using JSON and localStorage as shown below:

var db_fn, record_list, json_str;
db_fn       = TAFFY( [ { name : 'fred' } ] );
record_list = db_fn().get();
json_str    =  JSON.stringify( record_list );
localStorage.setItem( 'my_taffy_key', json_str ) );

To anyone else trying this code, make sure you remove that last closing parenthesis on the setItem line. That typo wasted 10 mins of my life 💃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants