A minimalistic implementation of asynchronous SQL for PHP.

Overview

libSQL

A minimalistic implementation of asynchronous SQL for PHP.

Installation via DEVirion

Install the DEVirion plugin and start your server. This will create a virions folder in your server's root directory.

server_root
| -> plugins
|    --> DEVirion.phar
| -> virions
  • Download pre-compiled .phar files can be downloaded from poggit.
  • Place the pre-compiled .phar in the virions directory

Running from source code

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 your src directory.

Examples

Retrieve all customer records

"sqlite", "sqlite" => [ "data-file" => "test.db" ] ] ); $query = new class extends SQLiteQuery { public function handleIncomingConnection(SQLite3 $connection): ?array { return $connection->query($this->getQuery())?->fetchArray() ?: null; } public function getQuery(): string { return "SELECT * FROM " . $this->getTable(); } }; $connector->submitQuery($query, "customers", function (?array $customers): void { if (!$customers) { echo "No customers found"; return; } foreach ($customers as $customer) { echo $customer["name"]; } }, function (PromiseError $error): void { echo "An error occurred with the message " . $error->getMessage(); } ); ">
$connector = new DatabaseConnector($this,
    [
        "provider" => "sqlite",
        "sqlite" => [
            "data-file" => "test.db"
        ]
    ]
);

$query = new class extends SQLiteQuery {

    public function handleIncomingConnection(SQLite3 $connection): ?array
    {
        return $connection->query($this->getQuery())?->fetchArray() ?: null;
    }

    public function getQuery(): string
    {
        return "SELECT * FROM " . $this->getTable();
    }
};

$connector->submitQuery($query, "customers",
    function (?array $customers): void {
        if (!$customers) {
            echo "No customers found";
            return;
        }
        foreach ($customers as $customer) {
            echo $customer["name"];
        }
    },
    function (PromiseError $error): void {
        echo "An error occurred with the message " . $error->getMessage();
    }
);

Create a new customer record

"sqlite", "sqlite" => [ "data-file" => "test.db" ] ] ); $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 handleIncomingConnection(SQLite3 $connection): bool { $statement = $connection->prepare($this->getQuery()); $statement->bindValue(":name", $this->getName()); $statement->bindValue(":lastName", $this->getLastName()); $statement->bindValue(":age", $this->getAge()); $statement->execute(); $statement->close(); return true; } public function getQuery(): string { return "INSERT OR IGNORE INTO " . $this->getTable() . " (name, lastName, age) VALUES (:name, :lastName, :age)"; } }; $connector->submitQuery($query, "customers", function (): void { echo "Successfully created a new record!"; }, function (PromiseError $error): void { echo "An error occurred with the message " . $error->getMessage(); } ); ">
$connector = new DatabaseConnector($this,
    [
        "provider" => "sqlite",
        "sqlite" => [
            "data-file" => "test.db"
        ]
    ]
);

$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 handleIncomingConnection(SQLite3 $connection): bool
    {
        $statement = $connection->prepare($this->getQuery());
        $statement->bindValue(":name", $this->getName());
        $statement->bindValue(":lastName", $this->getLastName());
        $statement->bindValue(":age", $this->getAge());
        $statement->execute();
        $statement->close();
        return true;
    }

    public function getQuery(): string
    {
        return "INSERT OR IGNORE INTO " . $this->getTable() . " (name, lastName, age) VALUES (:name, :lastName, :age)";
    }
};

$connector->submitQuery($query, "customers",
    function (): void {
        echo "Successfully created a new record!";
    },
    function (PromiseError $error): void {
        echo "An error occurred with the message " . $error->getMessage();
    }
);

Projects using libSQL

You might also like...
A Laravel package to output a specific sql to your favourite debugging tool. The supported log output is Laravel Telescope, Laravel Log, Ray, Clockwork, Laravel Debugbar and your browser.
A Laravel package to output a specific sql to your favourite debugging tool. The supported log output is Laravel Telescope, Laravel Log, Ray, Clockwork, Laravel Debugbar and your browser.

Laravel showsql A Laravel package to output a specific sql to your favourite debugging tool, your browser or your log file. Use case You often want to

API abstracting communication with SQL providers (eg: MySQL) on top of PDO inspired by Java JDBC

SQL Data Access API Table of contents: About Configuration Execution Installation Unit Tests Examples Reference Guide About This API is a ultra light

A data mapper implementation for your persistence model in PHP.

Atlas.Orm Atlas is a data mapper implementation for persistence models (not domain models). As such, Atlas uses the term "record" to indicate that its

Baum is an implementation of the Nested Set pattern for Laravel's Eloquent ORM.

Baum Baum is an implementation of the Nested Set pattern for Laravel 5's Eloquent ORM. For Laravel 4.2.x compatibility, check the 1.0.x branch branch

Adjacency List’ed Closure Table database design pattern implementation for the Laravel framework.

ClosureTable This is a database manipulation package for the Laravel 5.4+ framework. You may want to use it when you need to store and operate hierarc

A drop-in Doctrine ORM 2 implementation for Laravel 5+ and Lumen
A drop-in Doctrine ORM 2 implementation for Laravel 5+ and Lumen

Laravel Doctrine ORM A drop-in Doctrine ORM 2 implementation for Laravel 5+ $scientist = new Scientist( 'Albert', 'Einstein' ); $scientist-a

🔌 A Doctrine DBAL Driver implementation on top of Swoole Coroutine PostgreSQL extension

Swoole Coroutine PostgreSQL Doctrine DBAL Driver A Doctrine\DBAL\Driver implementation on top of Swoole\Coroutine\PostgreSQL. Getting started Install

Async Redis client implementation, built on top of ReactPHP.

clue/reactphp-redis Async Redis client implementation, built on top of ReactPHP. Redis is an open source, advanced, in-memory key-value database. It o

a distributed-redis-lock implementation for hyperf2.*

hyperf-redis-lock English | 中文 an easy redis-based distributed-lock implementation for hyperf 2.*。 This extension features distributed-lock includes b

Comments
  • SQLThread: Fixed infinite loop

    SQLThread: Fixed infinite loop

    Steps to reproduce the issue

    • Enable xdebug or recursionguard and start the server
    • Execute the stop command to stop the server
    • A recursive calling loop has been detected

    backtrace

    stop
    [09:19:57.187] [Server thread/INFO]: [CONSOLE: Stopping the server]
    [09:19:57.188] [Server thread/INFO]: Disabling DevTools v1.15.0
    [09:19:57.189] [Server thread/INFO]: Disabling DEVirion v1.2.8
    [09:19:57.189] [Server thread/INFO]: Disabling TNTTag v0.0.4
    [09:19:57.191] [Server thread/INFO]: Unloading world "world"
    [09:19:57.918] [Server thread/INFO]: Stopping other threads
    
    Fatal error: Uncaught Error: Reached maximum call depth of 256, aborting! in P:\game\test1\new\virions\libSQL_fork\src\cooldogedev\libSQL\thread\SQLThread.php:87
    Stack trace:
    #0 [internal function]: cooldogedev\libSQL\thread\SQLThread->cooldogedev\libSQL\thread\{closure}()
    #1 P:\game\test1\new\virions\libSQL_fork\src\cooldogedev\libSQL\thread\SQLThread.php(90): Threaded->synchronized(Object(Closure))
    #2 P:\game\test1\new\virions\libSQL_fork\src\cooldogedev\libSQL\thread\SQLThread.php(88): cooldogedev\libSQL\thread\SQLThread->quit()
    ...
    #378 [internal function]: cooldogedev\libSQL\thread\SQLThread->cooldogedev\libSQL\thread\{closure}()
    #379 P:\game\test1\new\virions\libSQL_fork\src\cooldogedev\libSQL\thread\SQLThread.php(90): Threaded->synchronized(Object(Closure))
    #380 phar://P:/game/test1/new/PocketMine-MP.phar/src/thread/ThreadManager.php(84): cooldogedev\libSQL\thread\SQLThread->quit()
    #381 phar://P:/game/test1/new/PocketMine-MP.phar/src/PocketMine.php(313): pocketmine\thread\ThreadManager->stopAll()
    #382 phar://P:/game/test1/new/PocketMine-MP.phar/src/PocketMine.php(328): pocketmine\server()
    #383 P:\game\test1\new\PocketMine-MP.phar(11): require('phar://P:/game/...')
    #384 {main}
      thrown in P:\game\test1\new\virions\libSQL_fork\src\cooldogedev\libSQL\thread\SQLThread.php on line 87
    
    Took too long to stop, server was killed forcefully!
    
    bug 
    opened by DaisukeDaisuke 1
  • outdated documentation

    outdated documentation

    The current documentation is outdated, it was originally made for version 0.0.2. Since version 0.0.3 the query submission no longer accepts parameters for the completion callback and error catcher as it returns the promise itself now.

    documentation 
    opened by cooldogedev 1
  • Server Crash

    Server Crash

    [01:20:19.207] [Server thread/CRITICAL]: ParseError: "Unclosed '(' on line 77 does not match '}'" (EXCEPTION) in "plugins/BedrockEconomy_dev-39.phar/src/cooldogedev/BedrockEconomy/libs/cooldogedev/libSQL/ConnectionPool" at line 95 --- Stack trace --- #0 pmsrc/vendor/pocketmine/classloader/src/BaseClassLoader(83): BaseClassLoader->loadClass(string[65] cooldogedev\BedrockEconomy\libs\cooldogedev\libSQL\ConnectionPool) cooldogedev/BedrockEconomy#1 plugins/BedrockEconomy_dev-39.phar/src/cooldogedev/BedrockEconomy/BedrockEconomy(90): BaseClassLoader->{closure}(string[65] cooldogedev\BedrockEconomy\libs\cooldogedev\libSQL\ConnectionPool) cooldogedev/BedrockEconomy#2 pmsrc/src/plugin/PluginBase(137): cooldogedev\BedrockEconomy\BedrockEconomy->onEnable() cooldogedev/BedrockEconomy#3 pmsrc/src/plugin/PluginManager(438): pocketmine\plugin\PluginBase->onEnableStateChange(true) cooldogedev/BedrockEconomy#4 pmsrc/src/Server(1383): pocketmine\plugin\PluginManager->enablePlugin(object cooldogedev\BedrockEconomy\BedrockEconomy#23590) cooldogedev/BedrockEconomy#5 pmsrc/src/Server(1009): pocketmine\Server->enablePlugins(object pocketmine\plugin\PluginEnableOrder#23437) cooldogedev/BedrockEconomy#6 pmsrc/src/PocketMine(303): pocketmine\Server->__construct(object BaseClassLoader#2, object pocketmine\utils\MainLogger#3, string[16] /home/container/, string[24] /home/container/plugins/) cooldogedev/BedrockEconomy#7 pmsrc/src/PocketMine(326): pocketmine\server() cooldogedev/BedrockEconomy#8 pmsrc(11): require(string[60] phar:///home/container/PocketMine-MP.phar/src/PocketMine.php)

    bug 
    opened by iSpaceYT 0
  • RawSQLQuery proposal

    RawSQLQuery proposal

    There are limitations when trying to submit a simple query that doesn't need a custom class, an example is a query that creates a table. This happens due to the fact that the query classes are an abstraction that you must extend in custom classes.

    enhancement 
    opened by cooldogedev 0
Releases(v0.0.4)
Owner
null
A php securised login system, using Hash, Salt and prevent from SQL Injections

A Basic Secure Login Implementation Hashed & Salted password ( only hashed in ShA-512 for now ) No SQL injection possible Prevent XSS attacks from the

Yohann Boniface 1 Mar 6, 2022
Tiny php mysql lib (PDO-based) with handy fetch/update functionality, supports both SQL and parametric queries

Micro PHP mysql lib (~ 200 lines of code) with ultra powerful CRUD for faster than ever development: parametric fetch/insert/update/delete (based on a

Mr Crypster 18 Dec 10, 2022
The Enobrev\ORM library is a small framework of classes meant to be used for simply mapping a mysql database to PHP classes, and for creating simply SQL statements using those classes.

The Enobrev\ORM library is a small framework of classes meant to be used for simply mapping a mysql database to PHP classes, and for creating simply SQL statements using those classes.

Mark Armendariz 0 Jan 7, 2022
SQL database access through PDO.

Aura.Sql Provides an extension to the native PDO along with a profiler and connection locator. Because ExtendedPdo is an extension of the native PDO,

Aura for PHP 533 Dec 30, 2022
Independent query builders for MySQL, PostgreSQL, SQLite, and Microsoft SQL Server.

Aura.SqlQuery Provides query builders for MySQL, Postgres, SQLite, and Microsoft SQL Server. These builders are independent of any particular database

Aura for PHP 424 Dec 12, 2022
ATK Data - Data Access Framework for high-latency databases (Cloud SQL/NoSQL).

ATK Data - Data Model Abstraction for Agile Toolkit Agile Toolkit is a Low Code framework written in PHP. Agile UI implement server side rendering eng

Agile Toolkit 257 Dec 29, 2022
A validating SQL lexer and parser with a focus on MySQL dialect.

SQL Parser A validating SQL lexer and parser with a focus on MySQL dialect. Code status Installation Please use Composer to install: composer require

phpMyAdmin 368 Dec 27, 2022
A SQL query builder with zero dependencies

Latitude Query Builder A SQL query builder with zero dependencies. Attempts to be PSR-1, PSR-2, and PSR-4 compliant. Install composer require latitude

Woody Gilk 618 Dec 30, 2022
SQL to Laravel Query Builder

Marwan - SQL To Laravel Builder SQL to Laravel Query Builder, A Converter written in PHP Features Converts SQL Queries to Laravel Query Builder. Assis

Rexhep Shijaku 162 Dec 19, 2022
Extract SQL statements from migrations

This is my package MigrationToSql To install: composer require bcleverly/migrationtosql --dev This repo is here to help you extract the SQL queries fr

Ben 4 Apr 15, 2022