darkterminal/turso-client-http 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

darkterminal/turso-client-http

最新稳定版本:v2.9.2

Composer 安装命令:

composer require darkterminal/turso-client-http

包简介

The Turso Client HTTP library is a PHP wrapper for Turso HTTP Database API

README 文档

README

TursoHTTP

The TursoHTTP library is a PHP wrapper for Turso HTTP Database API (Only). It simplifies interaction with Turso databases using the Hrana over HTTP protocol. This library provides an object-oriented approach to build and execute SQL queries with same API Interface like PHP Native Extension Turso Client PHP.

Shows a black logo in light color mode and a white one in dark color mode.

Requirements

  • Intention and Courage
  • Instinct as a Software Freestyle Engineer
  • Strong determination!
  • Turso Account
  • Don't forget to install PHP on your machine
  • A cup of coffee and the music you hate the most
  • Dancing (optional: if you are willing)

Features

Installation

You can install the TursoHTTP library using Composer:

composer require darkterminal/turso-client-http

Environment Variables

Variable Name Value Description
DB_URL or TURSO_URL Your Turso database URL -
DB_TOKEN or TURSO_TOKEN Your Turso database TOKEN -
DB_TIMEZONE or TURSO_TIMEZONE Asia/Jakarta See the list of timezones here
DB_STRICT_QUERY or TURSO_STRICT_QUERY true / default: false Use strict query when using explain method in Query Builder
DB_LOG_DEBUG or TURSO_LOG_DEBUG true / default: false Set Query logs to save all query activities into a log file
DB_LOG_NAME or TURSO_LOG_NAME libsql_debug Set Query channel name
DB_LOG_PATH or TURSO_LOG_PATH $HOME/.turso-http/logs/debug.log Log file location

Usage Example

use Darkterminal\TursoHttp\LibSQL;

require_once 'vendor/autoload.php';

$dbname     = getenv('DB_URL');
$authToken  = getenv('DB_TOKEN');
$db         = new LibSQL("dbname=$dbname&authToken=$authToken");

echo $db->version() . PHP_EOL;

$create_table = <<<SQL
CREATE TABLE IF NOT EXISTS users (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    name TEXT,
    email TEXT
)
SQL;

$db->execute($create_table);

LibSQL Schema Builder

<?php

use Darkterminal\TursoHttp\core\Enums\DataType;
use Darkterminal\TursoHttp\LibSQL;
use Darkterminal\TursoHttp\core\Builder\LibSQLBlueprint;
use Darkterminal\TursoHttp\core\Builder\LibSQLSchemaBuilder;

require_once 'vendor/autoload.php';

try {
    $dbname = getenv('DB_URL');
    $authToken = getenv('DB_TOKEN');

    $db = new LibSQL("dbname=$dbname&authToken=$authToken");
    $schemaBuilder = new LibSQLSchemaBuilder($db);

    // Creating table
    $schemaBuilder->create('contacts', function(LibSQLBlueprint $table) {
        $table->increments('id');
        $table->string('name');
        $table->unique('email');
        $table->string('phone');
        $table->timestamps();
    })->execute();

    echo "Table created successfully.\n";

    // Add new column in the table
    $schemaBuilder->table('contacts', function(LibSQLBlueprint $table) {
        $table->addColumn(DataType::TEXT, 'address');
    })->execute();

    echo "Column added successfully.\n";

    // Drop the table
    $schemaBuilder->drop('contacts')->execute();

    echo "Table contacts successfully dropped!.\n";
} catch (Exception $e) {
    echo "An error occurred: " . $e->getMessage();
}

Raw Query

<?php

use Darkterminal\TursoHttp\LibSQL;

require_once getcwd() . '/vendor/autoload.php';

$dbname     = getenv('DB_URL');
$authToken  = getenv('DB_TOKEN');
$db         = new LibSQL("dbname=$dbname;authToken=$authToken");

$query = <<<SQL
INSERT INTO contacts (name, email, phone, address) VALUES (?, ?, ?, ?)
SQL;

$db->execute($query, [
    'Imam Ali Mustofa',
    'darkterminal@duck.com',
    '08123456789',
    'Punk Univers'
]);

Query Builder

<?php

use Darkterminal\TursoHttp\LibSQL;
use Darkterminal\TursoHttp\core\Builder\LibSQLQueryBuilder;

require_once getcwd() . '/vendor/autoload.php';

$dbname = getenv('DB_URL');
$authToken = getenv('DB_TOKEN');
$db = new LibSQL("dbname=$dbname;authToken=$authToken");

$sql = new LibSQLQueryBuilder($db);

$contacts = $sql->table('contacts')
    ->where('address', '=', 'Punk Universe')
    ->get();

var_dump($contacts);

License

This library is licensed under the MIT License - see the LICENSE file for details.

统计信息

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

GitHub 信息

  • Stars: 50
  • Watchers: 2
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-08-30

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固