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

Qn: In memory database for react-native #83

Closed
bsr203 opened this issue Oct 10, 2018 · 9 comments
Closed

Qn: In memory database for react-native #83

bsr203 opened this issue Oct 10, 2018 · 9 comments
Assignees

Comments

@bsr203
Copy link
Contributor

bsr203 commented Oct 10, 2018

Hi,

I tried to use lokijs to run my test / storybook with sample data. Do you see issues using this adapter on react-native env. I currently get

error: bundling failed: Error: Unable to resolve module `fs` from `/Users/bsr/myApp/node_modules/lokijs/src/lokijs.js`: Module `fs` does not exist in the Haste module map
@radex
Copy link
Collaborator

radex commented Oct 10, 2018

You'd probably need to mock fs so that there's no bundler error, and also tweak the adapter initializer code so that you can use an in-memory database.

But you could also tweak the SQLite adapter to allow in-memory databases. That would be easier.

Both already work, but only in test environment. It wouldn't be difficult to change. I can give you pointers if you can send a pull request adding this capability.

@bsr203
Copy link
Contributor Author

bsr203 commented Oct 10, 2018

sure. may be sqlite inMemory mode is better as we don't need other drivers and dependencies. I think it will be useful for testing in isolation. thanks

@radex
Copy link
Collaborator

radex commented Oct 10, 2018

Well, I assume you're already using the React native native module for SQLite, so there's no extra dependencies.

Loki should work too in-memory. We use that in common tests (but that runs in Node)

@bsr203
Copy link
Contributor Author

bsr203 commented Oct 10, 2018

so is there an easy way to configure the adapter to pass through :memory config

@radex
Copy link
Collaborator

radex commented Oct 10, 2018

I already said:

Both already work, but only in test environment. It wouldn't be difficult to change. I can give you pointers if you can send a pull request adding this capability.

@bsr203
Copy link
Contributor Author

bsr203 commented Oct 10, 2018

:-) I was asking about the pointers you said. quickly searched through the codebase and didn't find the driver setting. Sorry, didn't look through all the code yet.

@radex
Copy link
Collaborator

radex commented Oct 11, 2018

@bsr203 You'll have to start from this branch, not master, as there were changes in this area:

https://github.com/Nozbe/WatermelonDB/pull/70/files#diff-010253597e9bd62ff04e3105667f6b66R45

right now, the database name is passed directly to sqlite only in test mode, otherwise documents filesystem path is prepended.

This can be changed so that if dbName is :memory: or contains mode=memory, it's passed directly without prepending FS path.

I think this should work on Android without any changes. But if no, this is the line:

https://github.com/Nozbe/WatermelonDB/pull/70/files#diff-2050916f6706022d034a09ab20dd9ed4R14

You'll find instructions for Xcode / Android setup and running native tests in CONTRIBUTING.md file

@bsr203
Copy link
Contributor Author

bsr203 commented Oct 11, 2018

@radex thanks for the details. I probably can't get to it right away, and let you know. thanks.

@radex
Copy link
Collaborator

radex commented Dec 7, 2018

Closing this. @bsr203 feel free to ask Qs if you want to get to implementing this in the future

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

2 participants