定制 darkterminal/libsql-doctrine-dbal 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

darkterminal/libsql-doctrine-dbal

最新稳定版本:0.0.3

Composer 安装命令:

composer require darkterminal/libsql-doctrine-dbal

包简介

A Doctribe DBAL Driver implementation on top of LibSQL Extension

README 文档

README

This repository is no longer under maintenance and has been moved to
the official Turso Database repository under the name Turso Doctrine DBAL

Turso + TypeScript

Turso + Doctrine DBAL

SQLite for Production. Powered by libSQL and libSQL Extension for PHP.

Turso · Quickstart · Examples · Docs · Discord · Blog & Tutorials

A LibSQL Driver for Doctrine DBAL

Latest Version on Packagist Total Downloads

LibSQL is a fork of SQLite and this package is #1 LibSQL Driver that run natively using LibSQL Native Extension/Driver/Whatever and support Doctrine DBAL.

Requirement

Before using this package, you need to install and configure LibSQL Native Extension for PHP. You can download from LibSQL Extension - Release

  1. 📦 Extract the archive
  2. 🗃 Locate somewhere in your machine
  3. 💽 Copy a relative path that address that extension/driver
  4. 📂 Open php.ini search ;extension if you using nano (ctrl+w) then searching for it
  5. 📝 add in the next-line extension=liblibsql_php.so (in Linux) without ; at the begining

Package Installation

composer require darkterminal/libsql-doctrine-dbal

Configuration

LibSQL has 4 types of connections to interact with the database: In-Memory Connection, Local Connection, Remote Connection, and Remote Replica Connection (Embedded Replica).

In-Memory Connection

$params = [
    "url"               => ":memory:",
    'driverClass'       => \Darkterminal\LibSQL\DBAL\Driver::class,
];

Local Connection

$params = [
    "url"               => "database.db",
    'driverClass'       => \Darkterminal\LibSQL\DBAL\Driver::class,
];

If you want to create Remote Connection or Remote Replica (Embedded Replica) Connection, you will need an existing database to continue. If you don’t have one, create one.

Get the database URL:

turso db show --url <database-name>

Get the database authentication token:

turso db tokens create <database-name>

If you use .env file, assign credentials to the environment variables inside .env.

TURSO_DATABASE_URL=
TURSO_AUTH_TOKEN=

Remote Connection

$params = [
    "auth_token"        => "<your-database-auth-token-from-turso>",
    "sync_url"          => "<your-database-url-from-turso>",
    'driverClass'       => \Darkterminal\LibSQL\DBAL\Driver::class,
];

Remote Replica (Embedded Replica) Connection

$params = [
    "url"               => "database.db",
    "auth_token"        => "<your-database-auth-token-from-turso>",
    "sync_url"          => "<your-database-url-from-turso>",
    "sync_interval"     => 5,    // Optional, default is: 5 in seconds
    "read_your_writes"  => true, // Optional, default is: true
    "encryption_key"    => "",   // Optional, default is: empty
    'driverClass'       => \Darkterminal\LibSQL\DBAL\Driver::class,
];

Usage

use Doctrine\DBAL\DriverManager;

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

$params = [
    "url"               => ":memory:",
    'driverClass'       => \Darkterminal\LibSQL\DBAL\Driver::class,
];

$db = DriverManager::getConnection($params);

$createTable = "CREATE TABLE IF NOT EXISTS users (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    name TEXT,
    age INTEGER
)";
$db->executeStatement($createTable);

$insertUsers = <<<SQL
INSERT INTO users (name, age) VALUES ('Budi Dalton', 49);
INSERT INTO users (name, age) VALUES ('Sujiwo Tedjo', 50);
SQL;

$db->getNativeConnection()->executeBatch($insertUsers);

$result = $db->executeQuery("SELECT * FROM users")->fetchAllAssociative();
var_dump($result);
$db->close();

Documentation

  1. Turso Quickstart — Learn how create and connect your first database.
  2. SDK Quickstart — Learn how to install and execute queries using the libSQL client.
  3. SDK Reference — Dive deeper with the libSQL SDK reference and examples.

What is Turso?

Turso is a SQLite-compatible database built on libSQL, the Open Contribution fork of SQLite. It enables scaling to hundreds of thousands of databases per organization and supports replication to any location, including your own servers, for microsecond-latency access.

Learn more about what you can do with Turso:

统计信息

  • 总下载量: 7
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-06-10