{"id":18264332,"url":"https://github.com/cooldogepm/libsql","last_synced_at":"2025-04-04T20:31:34.196Z","repository":{"id":50568630,"uuid":"401502580","full_name":"cooldogepm/libSQL","owner":"cooldogepm","description":"A minimalistic implementation of asynchronous SQL","archived":false,"fork":false,"pushed_at":"2024-04-02T22:32:38.000Z","size":72,"stargazers_count":23,"open_issues_count":0,"forks_count":6,"subscribers_count":0,"default_branch":"pm5","last_synced_at":"2025-03-20T19:07:52.801Z","etag":null,"topics":["asynchronous","library","mysql","php","sql","sqlite","threading"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cooldogepm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-08-30T22:27:56.000Z","updated_at":"2024-08-15T19:27:43.000Z","dependencies_parsed_at":"2024-11-05T11:16:59.225Z","dependency_job_id":null,"html_url":"https://github.com/cooldogepm/libSQL","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cooldogepm%2FlibSQL","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cooldogepm%2FlibSQL/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cooldogepm%2FlibSQL/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cooldogepm%2FlibSQL/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cooldogepm","download_url":"https://codeload.github.com/cooldogepm/libSQL/tar.gz/refs/heads/pm5","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247246461,"owners_count":20907803,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asynchronous","library","mysql","php","sql","sqlite","threading"],"created_at":"2024-11-05T11:14:23.045Z","updated_at":"2025-04-04T20:31:33.870Z","avatar_url":"https://github.com/cooldogepm.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# libSQL\n\nA minimalistic implementation of asynchronous [SQL](https://en.wikipedia.org/wiki/SQL) for PHP.\n\n### Usage\n\n#### Initialise the connection pool\n\n```php\n$pool = new ConnectionPool(PluginBase, [\n    \"provider\" =\u003e \"sqlite\",\n    \"threads\" =\u003e 2,\n    \"sqlite\" =\u003e [\n        \"path\" =\u003e \"test.db\"\n    ]\n]);\n```\n\n\u003cbr\u003e\n\n#### Examples\n\n###### Retrieve all customer records\n\n* Create the query class\n\n```php\nfinal class CustomerRetrievalQuery extends SQLiteQuery {\n    public function onRun(SQLite3 $connection): void {\n        $this-\u003esetResult($connection-\u003equery($this-\u003egetQuery())?-\u003efetchArray() ?: []);\n    }\n\n    public function getQuery(): string { return \"SELECT * FROM customers\"; }\n}\n```\n\n* Execute the query\n\n```php\n$query = new CustomerRetrievalQuery();\n$query-\u003eexecute(\n    onSuccess: function (array $customers): void {\n        foreach ($customers as $customer) {\n            echo $customer[\"name\"] . \" \" . $customer[\"lastName\"] . \": \" . $customer[\"age\"];\n            echo PHP_EOL;\n        }\n    },\n    onFailure: function (SQLException $exception): void {\n        echo \"Failed to retrieve customers due to: \" . $exception-\u003egetMessage();\n    }\n);\n```\n\n\u003cbr\u003e\n\n###### Create a new customer record\n\n* Create the query class\n\n```php\nfinal class CustomerCreationQuery extends SQLiteQuery {\n    public function __construct(\n        protected string $name,\n        protected string $lastName,\n        protected int    $age\n    ) {}\n\n    public function onRun(SQLite3 $connection): bool {\n        $statement = $connection-\u003eprepare($this-\u003egetQuery());\n\n        $statement-\u003ebindValue(\":name\", $this-\u003egetName());\n        $statement-\u003ebindValue(\":lastName\", $this-\u003egetLastName());\n        $statement-\u003ebindValue(\":age\", $this-\u003egetAge());\n        $statement-\u003eexecute();\n\n        $this-\u003esetResult($connection-\u003echanges() \u003e 0);\n\n        $statement-\u003eclose();\n    }\n\n    public function getQuery(): string {\n        return \"INSERT OR IGNORE INTO customers (name, lastName, age) VALUES (:name, :lastName, :age)\";\n    }\n\n    public function getName(): string { return $this-\u003ename; }\n    public function getLastName(): string { return $this-\u003elastName; }\n    public function getAge(): int { return $this-\u003eage; }\n}\n```\n\n* Execute the query\n\n```php\n$query = new CustomerCreationQuery(\"Saul\", \"Goodman\", 41);\n$pool-\u003esubmit(\n    query: $query,\n\n    onSuccess: function (bool $created): void {\n        echo $created ? \"Customer created successfully!\" : \"Customer already exists!\";\n    },\n    onFailure: function (SQLException $exception): void {\n        echo \"Failed to create the record due to: \" . $exception-\u003egetMessage();\n    }\n);\n```\n\n### Projects using libSQL\n- [BedrockEconomy](https://github.com/cooldogepm/BedrockEconomy)\n- [BuildBattle](https://github.com/cooldogepm/BuildBattle)\n- [TheBridges](https://github.com/cooldogepm/TheBridges)\n- [TNTTag](https://github.com/cooldogepm/TNTTag)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcooldogepm%2Flibsql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcooldogepm%2Flibsql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcooldogepm%2Flibsql/lists"}