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

rqlite (sqlite raft consensus) #17

Closed
pitsolu opened this issue Feb 9, 2025 · 9 comments
Closed

rqlite (sqlite raft consensus) #17

pitsolu opened this issue Feb 9, 2025 · 9 comments

Comments

@pitsolu
Copy link
Contributor

pitsolu commented Feb 9, 2025

Hi,

Hope you are well. Just like to first of all say I enjoy using pop framework.

This is more of a suggestion rather than an issue.

Raft consensus for sqlite is coming up quite well as a trend.

The problem is that they do not allow writing directly to the database but via a REST API so as to allow distribution.

How can this be accommodated in pop-db ?

@nicksagona
Copy link
Collaborator

Hey - thanks for your interest. I think that's a pretty interesting idea. I would think a possible direction to go would be to add another DB adapter, e.g. Pop\Db\Adapter\Rqlite that's built on top of the pop-http component, specifically the functionality that comes with Pop\Http\Client . Looking at the docs over at https://rqlite.io, it seems it could be done fairly easily.

@pitsolu
Copy link
Contributor Author

pitsolu commented Feb 17, 2025

Recently found a good package to use for rqlite. Would you consider integrating this into popdb if I did a pull request?

@nicksagona
Copy link
Collaborator

Probably not. It looks like it has its own ecosystem for adapters, results, etc. I'd be more interested in just building out an rqlite adapter using the Pop HTTP client, while leveraging the existing DB ecosystem in Pop DB.

@pitsolu
Copy link
Contributor Author

pitsolu commented Mar 9, 2025

Hi @nicksagona, still working on the rqlite adapter. Just got an error while using User::findById(5)

   TypeError  Pop\Db\Sql\PredicateSet::equalTo(): Argument #2 ($value) must be of type string, null given, called in src/Gateway/Row.php on line 244.

What might it mean?

@nicksagona
Copy link
Collaborator

Is the User record class set up correctly? Usually an error like that means that there's some misconfiguration with the table class (e.g., the primary keys, etc). Would have to see more of your code. Here's a basic example with a user table in a SQLite DB file (id, username, email columns, id is the PK and AI)

<?php

require_once __DIR__ . '/../vendor/autoload.php';

use Pop\Db\Db;
use Pop\Db\Record;

class User extends Record
{

}

Record::setDb(Db::sqliteConnect([
    'database' => __DIR__ . '/tmp/popdb.sqlite',
]));

$user = new User([
    'username' => 'admin',
    'email'    => '[email protected]',
]);
$user->save();

$user = User::findById(1);
print_r($user->toArray());

Will print out:

Array
(
    [id] => 1
    [username] => admin
    [email] => [email protected]
)

@pitsolu
Copy link
Contributor Author

pitsolu commented Mar 11, 2025

Still getting the same issue. Please see my code here.

User::findAll and User::findOne are working but User::findById is not.

Trace:

 0:  () at src/Sql/PredicateSet.php:211
 1:  Pop\Db\Sql\PredicateSet->equalTo() at src/Gateway/Row.php:244
 2:  Pop\Db\Gateway\Row->find() at src/Record.php:576
 3:  Pop\Db\Record->getById() at src/Record.php:296
 4:  Pop\Db\Record::findById() at eval()'d code:1

@pitsolu
Copy link
Contributor Author

pitsolu commented Mar 12, 2025

@nicksagona solved the issue.

The files below reference different adapters, so I added rqlite.

src/Sql/AbstractSql.php
src/Sql/Schema.php
src/Sql/Select.php

@pitsolu
Copy link
Contributor Author

pitsolu commented Mar 13, 2025

Hi @nicksagona,

I was wondering is you could change $u = new User to insert on save instead of update?

Example:

$u = new User(["username"=>"nick", email=>"[email protected]"]);
$u->save();// Does an INSERT

$u = User::findById(1);
$u->save();// Does an UPDATE

$u = new User;
$u->username = "sagona";
$u->email = "[email protected]"
$u->save();// Does and UPDATE instead of INSERT. Also gets an error. See below:
Pop\Db\Gateway\Exception  Error: The value of '0' is not set.

@pitsolu
Copy link
Contributor Author

pitsolu commented Mar 18, 2025

Hi @nicksagona,

After some contemplation I've decided I can do this externally without affecting popdb components.

You can have a look at it here.

I think you may close this "issue" at this point.

Thanks, much appreciated.

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

No branches or pull requests

2 participants