node-viewmodel icon indicating copy to clipboard operation
node-viewmodel copied to clipboard

Support for firestore

Open rickerbh opened this issue 6 years ago • 17 comments

I've added Google's Firebase Firestore as a data source/destination in view model. If there is anything else that needs to be implemented or supported to get this database into the package just let me know.

rickerbh avatar Jun 01 '18 04:06 rickerbh

wow cool. Is there a way to have tests?

just another idea: For simple queries, would it be possible to map mongodb like queries? I.e. this: aRepo.find({aProp: 'aValue'}, would be mapped to this: aRepo.find(['aProp', '==', 'aValue'], ?

adrai avatar Jun 01 '18 04:06 adrai

Looks great indeed! In addition to tests ( let us know if you need any help setting those up ), could you please adjust the documentation to use ES5 syntax, for it to be in tact with the rest?

nanov avatar Jun 01 '18 04:06 nanov

@adrai I've now included support for both mongodb like queries, as well as the firestore array syntax. @nanov I've updated the documentation as well, and (I think) got all of the ES6 out of there.

Regarding tests - what's the best way to set these up? Firestore is hosted by google, so credentials will be needed to get tests to hit the real implementation.

rickerbh avatar Jun 01 '18 06:06 rickerbh

Actually, I think I've got this. I'll change the .travis.yml file to write out an environment variable with the credentials in it to a file, and use that for authentication with Google. I'll get those changes back here soon.

rickerbh avatar Jun 01 '18 06:06 rickerbh

I've got all the tests passing now (bar the ones I've excluded with nested array support). I needed to add support for more functionality and concurrency checks - which is a good thing. I've also updated README.md with instructions on how to setup travis to work with the data store. Can you let me know if you feel anything is missing?

rickerbh avatar Jun 04 '18 00:06 rickerbh

looks good... is there a reason why the tests are excluded?

adrai avatar Jun 04 '18 04:06 adrai

Yes, it's because it would fail the tests if you merge to master, because the environment variable in your travis for the authentication with google won't be set up. I left the config for it commented out so you could add the authentication whenever you wanted, and wouldn't break existing tests.

rickerbh avatar Jun 04 '18 04:06 rickerbh

Hi, i have no experience with firestore, and correct me if I'm wrong, but it seems like this is aimed at testing.

nanov avatar Jun 04 '18 04:06 nanov

@nanov That's for testing cloud functions only - not the datastore itself. It simulates triggering the cloud functions once data in inserted/updated/deleted.

I might be able to use https://www.npmjs.com/package/mock-cloud-firestore to mock out the datastore if you like.

rickerbh avatar Jun 04 '18 05:06 rickerbh

Hmm, as said, i have zero experience with Google Firebase Firestore so I cannot really tell, what other options there are to achieve automated testing? Maybe setting up a dedicated test account by google for this library?

EDIT: Are those things usually done with this mock library?

nanov avatar Jun 04 '18 05:06 nanov

I had a look at that mocking library and it doesn't appear to support the features required for the concurrency checks. I think the only way to get automated testing is via setting up a dedicated account. But the owner of the project should probably own the account. I'm happy to set it up, and then transfer ownership to someone else.

rickerbh avatar Jun 04 '18 06:06 rickerbh

Ok... then you are the owner of the project (at least for this db implementation) ;-)

adrai avatar Jun 04 '18 15:06 adrai

Sorry for the long gap in communications - what's the best way to get the Firebase credentials to you? They shouldn't be exposed publicly.

rickerbh avatar Jul 20 '18 23:07 rickerbh

perhaps if i give you access to the repo, you can encrypt the credentials directly for travis? So they are never exposed. Never tried this...

adrai avatar Jul 21 '18 06:07 adrai

Hi, yes I can. That's no problem. Just need to paste in 1 variable in the config in travis, then uncomment the tests and it should just work. Let me know when access is granted, and I'll get it set up.

rickerbh avatar Jul 24 '18 06:07 rickerbh

invited ;-)

adrai avatar Jul 24 '18 06:07 adrai

Thanks for that. I've just had a look at travis and I can't see the project in my repositories list yet. Hopefully it'll appear after a sync or something.

rickerbh avatar Jul 24 '18 06:07 rickerbh