CrispyWaffle icon indicating copy to clipboard operation
CrispyWaffle copied to clipboard

[FEATURE] Add `CouchDB` support

Open guibranco opened this issue 1 year ago • 3 comments

Description

Add a new project, CrispyWaffle.CouchDB, with the following features:

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.

guibranco avatar Aug 13 '24 11:08 guibranco

Hey @guibranco, I can take this. What's in the TBD?

Mohammad-Haris avatar Aug 16 '24 10:08 Mohammad-Haris

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.

guibranco avatar Aug 16 '24 10:08 guibranco

@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 avatar Aug 16 '24 10:08 guibranco

@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 avatar Aug 22 '24 17:08 Mohammad-Haris

@Mohammad-Haris ohhh ok, in that case, no problem, I thought you were updating it manually, and it gets reverted after merge, haha

guibranco avatar Aug 22 '24 19:08 guibranco

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 avatar Sep 03 '24 01:09 Mohammad-Haris

@Mohammad-Haris, thanks for the feedback! I appreciate that. Cool, let me know if you need more context in anything!

guibranco avatar Sep 03 '24 09:09 guibranco

@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

Mohammad-Haris avatar Sep 04 '24 07:09 Mohammad-Haris

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.

guibranco avatar Sep 04 '24 08:09 guibranco

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?

Mohammad-Haris avatar Sep 04 '24 09:09 Mohammad-Haris

Yeah, no problem!

guibranco avatar Sep 04 '24 10:09 guibranco

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?

Mohammad-Haris avatar Sep 05 '24 05:09 Mohammad-Haris

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.

guibranco avatar Sep 05 '24 09:09 guibranco

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?

Mohammad-Haris avatar Sep 10 '24 05:09 Mohammad-Haris

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.

guibranco avatar Sep 10 '24 11:09 guibranco

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.

Mohammad-Haris avatar Sep 10 '24 13:09 Mohammad-Haris

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.

guibranco avatar Sep 10 '24 13:09 guibranco