CrispyWaffle
CrispyWaffle copied to clipboard
[FEATURE] Add `CouchDB` support
Description
Add a new project, CrispyWaffle.CouchDB, with the following features:
- Cache (implement the ICacheRepository interface)
Tech notes
- 💡 https://dev.to/matteobortolazzo/couchdb-and-c-efcore-like-queries-2ma4
- 💡 https://github.com/matteobortolazzo/couchdb-net
- 🤔 https://stackoverflow.com/questions/6482400/messaging-bus-event-storage-pubsub
- 👀 https://github.com/MattCollins84/couch-pubsub
Screenshots or Diagrams
No response
Additional information
~~This is a draft feature request. Feel free to add more context, use cases, and opinions.~~
We will proceed only with the cache features in this ticket.
Further, we might need additional features for the CouchDB project.
Hey @guibranco, I can take this. What's in the TBD?
We can implement the cache features only for now, and later in the future we can add more capabilities to this. I will remove the TBD notes and keep only the cache requirements.
@Mohammad-Haris, just be aware of the contributors-readme.yml workflow. It automatically updates the contributors' list, so you know you don't need to update it manually since the workflow run will override it.
@guibranco I never updated that file in the first place. It was always the same workflow on my fork. I think shows in the PR also that the changes in those files were by bot. So whenever I synced my fork with your repo, and not discard those commits, they appeared in the PR also. I disabled the workflow though, with my last commit. I don't see anymore of those commits in my fork now. Maybe we can disable the workflow for forks, I can look into it if needed.
@Mohammad-Haris ohhh ok, in that case, no problem, I thought you were updating it manually, and it gets reverted after merge, haha
I was a little busy elsewhere. Looked into it a bit on Sunday (new project and stuff). I have time this week. I can clear some open issues along with this.
@Mohammad-Haris, thanks for the feedback! I appreciate that. Cool, let me know if you need more context in anything!
@guibranco
The interface we have to implement has an unconstrained method definition T Get<T>(string key). To get a database using CouchDB.NET library we need a document derived from CouchDocument, due to this constraint CouchDatabase<TSource> GetDatabase<TSource>() where TSource : CouchDocument. How are we to move forward here?
CouchDB.NET version: 1.2.2
We can implement it as required by the library and create a proxy method inherited from the interface that hard-casts the T to CouchDocument, so we end up with both public methods.
The public method we create according to the library needs won't be visible from an ICacheRepository type and ICacheRepository original method implementation will kind of downgrade every type to CouchDocument.
That's OK?
Yeah, no problem!
What to do of TTL for CouchDB? Create an internal system which tracks time of each added entity and then removes it if time expires?
We can have a base document with expire field on it. The base document can have a field ttl or expires_at and stamp a timestamp indicating when it will become invalid or expired.
So, when we retrieve the document from the persistence, we also check for this field and ensure it is still in the future (I suggest using UTC for that), and if it's not, we just return null/default for that item.
Completed the basic dev and testing related to this today. I added some tests. They work locally but I glanced over the workflows on this repo and didn't find a test running one, is there one that runs tests?
Also what is the purpose of subKey in get and set methods in ICacheRepository if key can uniquely identify a document? Did I miss something?
Hi @Mohammad-Haris ,
The tests run in AppVeyor CI.
Regarding the subKey its a feature to access hashes/dictionaries.
In Redis (the main Cache implementation), we have this feature, so it was added.
In Memory, we use a compound key to have subKey effect.
For the CouchDB implementation, we can use the MemoryCache implementation or throw a NotImplementedException, which is up to us.
So we will have to start a CouchDB service on appveyor to make the tests pass? Because the tests currently rely on the local CouchDB service running on my machine.
Yes, you will need to add 2-3 lines to the appveyor.yml file:
install:
- ps: (new-object net.webclient).DownloadFile('https://couchdb.neighbourhood.ie/downloads/3.3.3-3/win/apache-couchdb-3.3.3-3.msi', 'apache-couchdb-3.3.3.msi')
- ps: msiexec /i apache-couchdb-3.3.3.msi /quiet ADMINUSER=admin ADMINPASSWORD=myP@ssw0rd /norestart
This should be enough to download and start CouchDB 3.3.3 on the CI.