Add adapters for Cloudflare D1 (binding & http)
Adapters for Cloudflare D1. Includes createD1DataProvider and createD1HttpDataProvider to demonstrate usage.
There is also a few minor type fixes and dependency updates to get npm run build to work (this is independent of the D1 additions).
Codecov Report
Attention: Patch coverage is 72.72727% with 21 lines in your changes missing coverage. Please review.
Project coverage is 86.90%. Comparing base (
dda7fd4) to head (6552de4). Report is 1 commits behind head on main.
| Files with missing lines | Patch % | Lines |
|---|---|---|
| projects/core/remult-d1-http.ts | 40.00% | 12 Missing :warning: |
| projects/core/remult-d1.ts | 83.92% | 9 Missing :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## main #717 +/- ##
==========================================
+ Coverage 86.80% 86.90% +0.09%
==========================================
Files 100 102 +2
Lines 15991 16306 +315
Branches 3816 3830 +14
==========================================
+ Hits 13881 14170 +289
- Misses 2110 2136 +26
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
Started my demo here: https://github.com/nerdfolio/remult/pull/1
I added tests for d1 using wrangler getPlatformProxy, removed h3 as peer dev, and made some minor fixes to make typescript happy for the npm run build-tests script.
Are we merge-ready?
It would be nice to have this merged into remult so I don't have to maintain a local version. Chances are it will be only me that's using it for next next few weeks to workout kinks if any. Easier to do that if the code is merged imo, but your call.
As for d1-http, testing would be similar to Turso in the sense that you'd have to setup cloudflare credentials and an actual project with apiKey and databaseId to use. The d1-http use case is not really meant for production but for occasional viewing of the production db (via remult-admin perhaps) or one-off scripts that's inititated from the local computer (or anywhere outside of cloudflare platform). It's useful but it's mostly meant to be a dev tool. remult-d1 is the main production driver.
It would be nice to have this merged into remult so I don't have to maintain a local version. Chances are it will be only me that's using it for next next few weeks to workout kinks if any. Easier to do that if the code is merged imo, but your call.
As for
d1-http, testing would be similar to Turso in the sense that you'd have to setup cloudflare credentials and an actual project with apiKey and databaseId to use. Thed1-httpuse case is not really meant for production but for occasional viewing of the production db (via remult-admin perhaps) or one-off scripts that's inititated from the local computer (or anywhere outside of cloudflare platform). It's useful but it's mostly meant to be a dev tool.remult-d1is the main production driver.
Hey Tai 👋,
We are not that comfortable in publishing d1-http like this, without tests but part of the public remult API.
May you remove d1-http for the PR and start with d1 first ?
I'll update doc (& landing) with d1 as soon as we merge this one.
Thanks a lot.
Side question, your code is also on Cloudflare ? Or just d1 ?
@taivo alternatively - if you have working tests for http that require a cloud account for it. you can store that account in an environment variable - and run the tests on your machine before you push.
Later we'll add an environment variable on the CI to run these tests there - but I want to make sure that its covered and tested before we add this to the root of our public api
No problem, guys. Give me a few days. I'll set up d1-http tests. Keep up the good work!
Hi guys, here is the test for d1-http. Works from my laptop with my cloudflare credentials.
I had to set the timeout for this test suite to 15s (instead of vitest default 5s). The number roundtrips over the internet needed to carry out this array insert https://github.com/remult/remult/blob/main/projects/tests/dbs/shared-tests/test-aggregate.ts#L68-L199 is the culprit (and prob due to my location and internet speed).
Real root cause seems to be these lines https://github.com/remult/remult/blob/main/projects/core/src/remult3/RepositoryImplementation.ts#L553-L557 . It looks like data providers that aren't isProxy === true carry out array inserts 1 item at a time.
I don't understand enough about proxy data providers at this point to go deeper than that.
Lmk if this works.
Hi guys, here is the test for d1-http. Works from my laptop with my cloudflare credentials.
I had to set the timeout for this test suite to 15s (instead of vitest default 5s). The number roundtrips over the internet needed to carry out this array insert https://github.com/remult/remult/blob/main/projects/tests/dbs/shared-tests/test-aggregate.ts#L68-L199 is the culprit (and prob due to my location and internet speed).
Real root cause seems to be these lines https://github.com/remult/remult/blob/main/projects/core/src/remult3/RepositoryImplementation.ts#L553-L557 . It looks like data providers that aren't
isProxy === truecarry out array inserts 1 item at a time.I don't understand enough about proxy data providers at this point to go deeper than that.
Lmk if this works.
Non proxy databases are meant to be with minimum latency between remult and the db. A proxy database is essencially the http data provider - that relays all requests to the remult server to perform.
Looks great to me 👍 Formating and me merge ?