superfly / litefs

FUSE-based file system for replicating SQLite databases across a cluster of machines
Apache License 2.0
3.82k stars 93 forks source link

LiteFS PHP Client? #293

Closed nickchomey closed 1 year ago

nickchomey commented 1 year ago

Hi there, I'd like to explore using LiteFS with Wordpress now that they are implementing a SQLite backend. Is there any sort of PHP client for using LiteFS? Or any other suggestions for how I'd make this happen? Thanks!

savikko commented 1 year ago

You can use just general SQLite client for PHP. Then, on "lower level" litefs will take care of things. Wordpress does not have to know that litefs is involved.

So, on the server where you are running Wordpress, you would have just one extra process running litefs. Then, you would point Wordpress to read SQLite file/database which is accessible on fuse.dir (defined on litefs.yml).

benbjohnson commented 1 year ago

Yep, @savikko is correct. We got Wordpress working on LiteFS although we had an issue with getting writes to forward to the primary. However, that was before we added the built-in HTTP proxy that's coming in v0.4.0. Now that the proxy is in place, it should be a lot easier to get working.

I'm hoping to get a v0.4.0 release out this week and I'll push some docs up for the proxy as well.

nickchomey commented 1 year ago

Thanks!

There doesn't seem to be any documentation about how to actually query/interact with the underlying SQLite db. So, perhaps my issue is that I assumed that Litefs has its own API (as seems to be the case with rqlite) which therefore requires a client. Is that wrong?

I had written off litefs on this basis, and was starting to look into using Marmot (which seems wonderful with its leaderless architecture and accepts sqlite syntax) but less-developed. Also, WordPress can't really take advantage of the leaderless mechanism due to the way it's db is structured.

So, does litefs just use standard SQLite syntax as well, as suggested by your answers, and therefore would just be a "drop-in" replacement for the standard WordPress SQLite implementation (currently under development)?

When you get a chance after 0.4.0 release, some more documentation on CRUD with litefs would be great (as well as anything WordPress-specific if you have it handy!)

nussjustin commented 1 year ago

There doesn't seem to be any documentation about how to actually query/interact with the underlying SQLite db. So, perhaps my issue is that I assumed that Litefs has its own API (as seems to be the case with rqlite) which therefore requires a client. Is that wrong?

SQLite with LiteFS is just standard SQLite.

All the magic happens on the filesystem level and is completely abstracted away from the application.

Your application doesn't need to know anything about LiteFS.

All you need to do for your application to use LiteFS is to create your SQLite database in the directory specified by fuse.dirand LiteFS will take care of the rest. If you already have an existing SQLite database file you can import it using litefs import.

No changes to any code should be required and no to the configuration other than the path to the database.

So, does litefs just use standard SQLite syntax as well, as suggested by your answers, and therefore would just be a "drop-in" replacement for the standard WordPress SQLite implementation (currently under development)?

Yes, since it is really just standard SQLite.

nickchomey commented 1 year ago

Perfect, thanks! I look forward to trying it out!