A minimalistic implementation of asynchronous SQL for PHP.
$pool = new ConnectionPool($this,
[
"provider" => "sqlite",
"sqlite" => [
"file" => "test.db"
]
]
);
$query = new class extends SQLiteQuery {
public function onRun(SQLite3 $connection): void
{
$this->setResult($connection->query($this->getQuery())?->fetchArray() ?: null);
}
public function getQuery(): string
{
return "SELECT * FROM " . $this->getTable();
}
};
$pool->submit($query, "customers",
context: ClosureContext::create(
function (?array $customers): void {
if (!$customers) {
echo "No customers found";
return;
}
foreach ($customers as $customer) {
echo $customer["name"];
}
},
)
);
$query = new class extends SQLiteQuery {
public function __construct(
protected string $name = "John",
protected string $lastName = "Smith",
protected int $age = 40
) {}
public function getName(): string { return $this->name; }
public function getLastName(): string { return $this->lastName; }
public function getAge(): int { return $this->age; }
public function onRun(SQLite3 $connection): void
{
$statement = $connection->prepare($this->getQuery());
$statement->bindValue(":name", $this->getName());
$statement->bindValue(":lastName", $this->getLastName());
$statement->bindValue(":age", $this->getAge());
$statement->execute();
$statement->close();
}
public function getQuery(): string
{
return "INSERT OR IGNORE INTO " . $this->getTable() . " (name, lastName, age) VALUES (:name, :lastName, :age)";
}
};
$pool->submit($query, "customers",
context: ClosureContext::create(
function (): void {
echo "Successfully created a new customer record";
},
)
);
Clone the repository via git git clone [email protected]:cooldogedev/libSQL.git
. This will create a libSQL
folder in your directory.
your_plugin
| -> src
| --> cooldogedev
| --> libSQL
- Place the
cooldogedev\libSQL
folder in yoursrc
directory.