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

Implement Cloudflare D1 driver #39

Closed
invisal opened this issue Mar 21, 2024 · 16 comments · Fixed by #116
Closed

Implement Cloudflare D1 driver #39

invisal opened this issue Mar 21, 2024 · 16 comments · Fixed by #116
Assignees

Comments

@invisal
Copy link
Collaborator

invisal commented Mar 21, 2024

No description provided.

@invisal invisal self-assigned this Mar 21, 2024
@avevotsira avevotsira assigned avevotsira and unassigned invisal Apr 7, 2024
@Chinoman10
Copy link

Chinoman10 commented Jul 18, 2024

If it helps, there's this other REPO that serves as a "D1 browser" of sorts:
https://github.com/JacobLinCool/d1-manager

I very much prefer this (libsql) interface however. Would love to also open and edit local .sqlite files so I don't have to use https://sqliteviewer.app/ (which actually doesn't allow editing), but I see there's an issue for that too I think ( #70 ).

@invisal
Copy link
Collaborator Author

invisal commented Jul 18, 2024

If it helps, there's this other REPO that serves as a "D1 browser" of sorts: https://github.com/JacobLinCool/d1-manager

I very much prefer this (libsql) interface however. Would love to also open and edit local .sqlite files so I don't have to use https://sqliteviewer.app/ (which actually doesn't allow editing), but I see there's an issue for that too I think ( #70 ).

LibSQL Studio can also open .sqlite file. We have SQLite playground
https://libsqlstudio.com/playground/client

You can click open or drag file in.

For Cloudflare D1, it shouldn't be difficult to implement, just we are not sure if there is high demand for this Cloudflare D1. The only challenge is CORS. But we can bypass it by proxy the request via our server.

Look like, it is time to get my hand dirty with Cloudflare D1 driver for our editor

@Chinoman10
Copy link

I just tested it out!

Few things:

  • Drag & drop didn't work; it would always open a new tab instead 🤷
  • Once I picked the .sqlite file from the filesystem, it opened without a hitch 👍
  • I was expecting it to make a select * from <insert-table-name> limit 50 when I (single) clicked a table's name on the left, but when it didn't do anything other than select it, I simply double-clicked and it "opened" as expected.
  • Making changes and committing them makes sense in a DB environment, however I was expecting the commit to change the DB on my FS that I had opened (so, actually "opening" the file, rather than "uploading" it). I had to realize that to use the changes I made, I had to download the DB and replace the original file with the "dump" (which is the DB itself, not an actual dump file (which AFAIK are usually sets of instructions to achieve the same DB state)).

Despite those nuances, this was good enough that I'll start using it instead of sqliteviewer moving forward :) and obviously recommend it to other folks too.

As far as D1 goes, it would make my day good sir <3 I hope one day I am able to pay it back ^^ I love FOSS and I'd love to reach a position where I can support these projects :)

@invisal
Copy link
Collaborator Author

invisal commented Jul 19, 2024

@Chinoman10

Drag & drop didn't work; it would always open a new tab instead 🤷

What are you trying to drag that open new tab?

however I was expecting the commit to change the DB on my FS that I had opened

This is limitation of the browser (for security reason). The only way to workaround is to make it as browser extension which allows to save back to opened file.

As far as D1 goes, it would make my day good sir

Let me try to finish the D1 this weekend. It shouldn't be hard to implement

@invisal invisal assigned invisal and unassigned avevotsira Jul 19, 2024
@Chinoman10
Copy link

@Chinoman10

Drag & drop didn't work; it would always open a new tab instead 🤷

What are you trying to drag that open new tab?

A .sqlite file (a local SQLite DB).

however I was expecting the commit to change the DB on my FS that I had opened

This is limitation of the browser (for security reason). The only way to workaround is to make it as browser extension which allows to save back to opened file.

Makes sense I think, thanks for explaining 🙏 I think the 'extension workaround' is what Google did so people could work on their G. Docs, etc. offline.

As far as D1 goes, it would make my day good sir

Let me try to finish the D1 this weekend. It shouldn't be hard to implement

There's no rush to it, but I'd be super happy about it for sure ^^
I'm wondering how you'll get the access going though, there's multiple ways to get it done.

  • Cloudflare API Keys with access to the D1s of the account;
  • Through native Cloudflare DB bindings (that's how "D1 Manager" does it) through the dashboard (or the wrangler.toml file)...

Other than that I'm not sure if there are other ways that don't involve a wrapper (that would need a native way to connect anyway, so would be pointless).

@invisal
Copy link
Collaborator Author

invisal commented Jul 19, 2024

We will use API Key which is how TablePlus and Dataflare are using.

@invisal
Copy link
Collaborator Author

invisal commented Jul 20, 2024

For save directly to file when open local SQLite file. I saw this https://developer.chrome.com/docs/capabilities/web-apis/file-system-access maybe it is possible

@invisal invisal linked a pull request Jul 20, 2024 that will close this issue
@invisal
Copy link
Collaborator Author

invisal commented Jul 20, 2024

@Chinoman10 Cloudflare driver is done. It will be available in the next release which will be on Monday 22th this month.

@Chinoman10
Copy link

@Chinoman10 Cloudflare driver is done. It will be available in the next release which will be on Monday 22th this month.

Just wanted to say that I tried it out today with a few D1 DBs and so far the experience has been great, thank you so much for building this out!
Right now I'm just using it locally on my browser (tho I did create a new account because I like the project!), but I might try self-hosting it one day.

Feel free to let me know how I can further support this project beyond giving a star on this repo and spreading the word :)

@invisal
Copy link
Collaborator Author

invisal commented Jul 24, 2024

@Chinoman10 for editing local sqlite, I also make some improvement

https://x.com/invisal89/status/1815738517240386035

@Chinoman10
Copy link

You should tag https://x.com/libsqlstudio on your profile, and make more posts from that account :)
I followed both! And also reposted your post 👍

Also, I did try opening a local SQLite DB first, but for some reason it isn't working for me.

  1. I tried drag-and-drop, no dice... no reaction what-so-ever;
  2. I click on 'Open', and it also does nothing.

Could it be something browser specific? I'm using Brave.

Console log shows:

7514-05c456c095fa9e61.js:1 Injecting message into window object
2page-26784bc94350aad5.js:6 Uncaught TypeError: n[0].getAsFileSystemHandle is not a function
    at HTMLDocument.e (page-26784bc94350aad5.js:6:395)
fd9d1056-7d5416ef79e4b900.js:1 Uncaught TypeError: window.showOpenFilePicker is not a function
    at onClick (page-26784bc94350aad5.js:6:2317)
    at Object.a_ (fd9d1056-7d5416ef79e4b900.js:1:72147)

@invisal
Copy link
Collaborator Author

invisal commented Jul 24, 2024

@Chinoman10 Brave for some reason does not support https://developer.mozilla.org/en-US/docs/Web/API/FileSystemHandle I think I need to do fallback for browser that does not support this one. Safari, Chrome, Edge and Firefox support this already. I will investigate which other browser that does not support.

@invisal
Copy link
Collaborator Author

invisal commented Jul 24, 2024

Brave does support it but you need to enable the flag

brave/brave-browser#18979

@Chinoman10
Copy link

Chinoman10 commented Jul 24, 2024

Brave does support it but you need to enable the flag
brave/brave-browser#18979

Perfect! <insert chef's kiss meme>
Thank you 🙏 ( edit: in case it wasn't obvious, I tested opening, reading, editing, committing and saving, and everything worked as expected 🎉 )

( I have one last question (off-topic for this issue tho): will you consider adding Postgres as well someday? We're currently using Adminer and it feels like I'm using a decades old product... and I think it's done in PHP too 🤮 )

@invisal
Copy link
Collaborator Author

invisal commented Jul 24, 2024

@Chinoman10
Eventually, we will support MySQL and PostgreSQL (it is where big audience). But I am not sure what will be the timeline.

LibSQL Studio is very new. (6~7 months old). So we need to catch up with other GUI in term of feature first before we expand to more drivers.

The good thing is that I used to write PostgreSQL/MySQL GUI (https://github.com/querymx/querym) before as well, so when I want to implement those driver, I will have some existing code before. ^^

@Chinoman10
Copy link

That's pretty dope! I might download that one and give it a shot when I feel frustrated about Adminer again 😅
Looking forward to your next releases of LibSQL, I'll try and follow closely ^^ (and help spread the word)

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

Successfully merging a pull request may close this issue.

3 participants