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

Enable foreign keys with LazyDatabase. #27

Open
bartvanhoutte opened this issue Nov 22, 2019 · 6 comments
Open

Enable foreign keys with LazyDatabase. #27

bartvanhoutte opened this issue Nov 22, 2019 · 6 comments
Labels
help wanted Extra attention is needed new feature New feature or request
Milestone

Comments

@bartvanhoutte
Copy link

Small support request/possible feature request. I would like to use foreign keys in my SQLite database and according to the SQLite documentation I have to enable this per connection via PRAGMA foreign_keys = ON.
Is there a way to execute this command everytime LazyDatabase creates a connection to the database?

@bartvanhoutte
Copy link
Author

I've currently worked around the issue by enabling FKs every time when selecting/updating/deleting, but this obviously isn't ideal ...

@clue clue added help wanted Extra attention is needed new feature New feature or request labels Nov 29, 2019
@clue
Copy link
Owner

clue commented Nov 29, 2019

@bartvanhoutte Thanks for reporting!

This is indeed not currently supported and your feature request makes perfect sense.

It's my understanding we should probably provide some API to pass arbitrary commands that are executed once the underlying connection is ready or do you think it makes more sense to provide some predefined ones?

@bartvanhoutte
Copy link
Author

bartvanhoutte commented Dec 2, 2019

Looking at the amount of options available to be configured this way I think it makes more sense to somehow provide an array of queries to be executed when a connection is made.

Something like this would suffice I guess:

$options['onConnect'][] = 'PRAGMA foreign_keys = on';
$options['onConnect'][] = 'PRAGMA threads = 4';
$db = (new DatabaseFactory($loop))->openLazy($path, $flags, $options);

What do you think?

@clue
Copy link
Owner

clue commented Nov 10, 2021

Here's my concept for a future SqliteClient API as discussed in #47:

$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));

The idea is to fire the open event immediately after the database is ready to accept commands, right before the query passed to query() would actually be executed.

What do you think about this?

@clue clue added this to the v2.0.0 milestone Nov 12, 2021
@Stevemoretz
Copy link

Sounds good to me!

@bartvanhoutte
Copy link
Author

@clue excellent.

@clue clue modified the milestones: v2.0.0, v3.0.0 Dec 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed new feature New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants