Skip to content

Support to issue initial queries #67

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

Closed
hvt opened this issue Jul 2, 2023 · 3 comments
Closed

Support to issue initial queries #67

hvt opened this issue Jul 2, 2023 · 3 comments
Labels
new feature New feature or request

Comments

@hvt
Copy link

hvt commented Jul 2, 2023

Hey there, neat idea to make DB access async by using UNIX sockets and a separate process.

I was wondering about something in regard to this. I'm using the LazyDatabase primitive, to minimize opening the database when nothing is actually queried.

In regard to SQLite, most of the times I'm using the WAL mode. But I find it a hassle to bother a user of the DatabaseInterface to always issue the PRAGMA journal_mode=wal query first, before querying anything else.

So is there any other way to enable the WAL mode? Is it perhaps possible to adapt the journal_mode using any of the $flags? (I could not find much information what flags are available.)

If that's not the case, I guess emitting an open event when the connection was actually opened -- with the DatabaseInterface instance as the event's first argument -- would really help.

In that case one could:

$db->on('open', function(DatabaseInterface $db) {
    $db->exec('PRAGMA journal_mode=wal;'));
});
@hvt
Copy link
Author

hvt commented Jul 2, 2023

(I have to admit that TIL that setting the journal mode to WAL is a persistent setting. So the initial query I imagined I needed, is not needed anymore. But still, would like to discuss how one would issue initial queries using this wonderful library :).)

@SimonFrings SimonFrings added new feature New feature or request duplicate labels Jul 6, 2023
@SimonFrings
Copy link
Contributor

Hey @hvt, thank you for taking the time and bringing in your ideas to improve this project 👍

There's actually an open feature request for this in #27. In there @clue described how a future SqliteClient concept could look like (#47), pretty similar to what you're suggesting:

$db = new Clue\React\Sqlite\SqliteClient('users.db');

$db->on('open', fn () => $db->exec('PRAGMA foreign_keys = on'));

$db->query('SELECT 1')->then(fn (QueryResult $result) => var_dump($result));

At the moment, we don't have any specific plans for when this will go live and as a result, I'm unable to provide you with an estimated timeline for its introduction in this project. @clue and I are working on a lot of different open source projects with the focus on ReactPHP and Framework X, so we'll keep you posted once we find the time to look into this 👍

If you need this urgently, you can also reach out to us or help us by becoming as sponsor ❤️

@hvt
Copy link
Author

hvt commented Jul 6, 2023

Hey @SimonFrings, sorry I did not find the feature request #27, but that was indeed exactly what I need.

I'm good for now, did some ugly facading, so I just wait for the next good release to arrive.

Bon boyage on all the ReactPHP & Framework X stuff 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants