DBD-libsql

 view release on metacpan or  search on metacpan

META.json  view on Meta::CPAN

            "Test::CPAN::Meta" : "0",
            "Test::MinimumVersion::Fast" : "0.04",
            "Test::PAUSE::Permissions" : "0.07",
            "Test::Pod" : "1.41",
            "Test::Spellunker" : "v0.2.7"
         }
      },
      "runtime" : {
         "requires" : {
            "DBI" : "1.631",
            "HTTP::Request" : "6.00",
            "IO::Socket::SSL" : "2.00",
            "JSON" : "4.00",
            "LWP::UserAgent" : "6.00",
            "Protocol::WebSocket" : "0.20",
            "perl" : "5.018"
         }
      },
      "test" : {
         "requires" : {
            "DBD::SQLite" : "1.66",

META.yml  view on Meta::CPAN

    file: lib/DBD/libsql/Hrana.pm
    version: '0.06'
  DBD::libsql::db:
    file: lib/DBD/libsql.pm
  DBD::libsql::dr:
    file: lib/DBD/libsql.pm
  DBD::libsql::st:
    file: lib/DBD/libsql.pm
requires:
  DBI: '1.631'
  HTTP::Request: '6.00'
  IO::Socket::SSL: '2.00'
  JSON: '4.00'
  LWP::UserAgent: '6.00'
  Protocol::WebSocket: '0.20'
  perl: '5.018'
resources:
  bugtracker: https://github.com/ytnobody/p5-DBD-libsql/issues
  homepage: https://github.com/ytnobody/p5-DBD-libsql
  repository: https://github.com/ytnobody/p5-DBD-libsql.git
version: '0.06'

README.md  view on Meta::CPAN

- All standard DBI methods are supported
- Some DBD-specific attributes (like last\_insert\_id) may have limitations
- Prepared statements use Hrana protocol parameter binding

# DEPENDENCIES

This module requires the following Perl modules:

- DBI (1.631 or later)
- LWP::UserAgent (6.00 or later)
- HTTP::Request (6.00 or later)
- JSON (4.00 or later)
- IO::Socket::SSL (2.00 or later) - for HTTPS connections

# AUTHOR

ytnobody <ytnobody@gmail.com>

# LICENSE

This library is free software; you can redistribute it and/or modify

cpanfile  view on Meta::CPAN

requires 'perl', '5.018';
requires 'DBI', '1.631';
requires 'LWP::UserAgent', '6.00';
requires 'HTTP::Request', '6.00';
requires 'JSON', '4.00';
requires 'IO::Socket::SSL', '2.00';
requires 'Protocol::WebSocket', '0.20';

on 'test' => sub {
    requires 'Test::More', '0.98';
    requires 'DBD::SQLite', '1.66';  # for testing comparison
};

on 'develop' => sub {

lib/DBD/libsql.pm  view on Meta::CPAN

package DBD::libsql;

# ABSTRACT: DBI driver for libsql databases

use 5.018;
use strict;
use warnings;
use DBI ();
use LWP::UserAgent;
use HTTP::Request;
use JSON;
use Data::Dumper;

our $VERSION = '0.06';
our $drh;

# Global hash to store HTTP clients keyed by database handle reference
our %HTTP_CLIENTS = ();

sub driver {

lib/DBD/libsql.pm  view on Meta::CPAN

    $dbh->STORE('libsql_dbh_id', $dbh_id);
    
    # Test connection to libsql server
    my $health_response = $ua->get("$server_url/health");
    unless ($health_response->is_success) {
        die "Cannot connect to libsql server at $server_url: " . $health_response->status_line;
    }
    
    # Initialize session baton with a simple query
    eval {
        my $init_request = HTTP::Request->new('POST', "$server_url/v2/pipeline");
        $init_request->header('Content-Type' => 'application/json');
        
        # Add Turso authentication header if token is available
        if ($auth_token) {
            $init_request->header('Authorization' => 'Bearer ' . $auth_token);
        }
        
        my $init_data = {
            requests => [
                {

lib/DBD/libsql.pm  view on Meta::CPAN

                    }
                }
            ]
        };
        
        # Add baton if available for session continuity
        if ($client_data->{baton}) {
            $pipeline_data->{baton} = $client_data->{baton};
        }
        
        my $request = HTTP::Request->new('POST', $client_data->{base_url} . '/v2/pipeline');
        $request->header('Content-Type' => 'application/json');
        
        # Add Turso authentication header if token is available
        if ($client_data->{auth_token}) {
            $request->header('Authorization' => 'Bearer ' . $client_data->{auth_token});
        }
        
        $request->content($client_data->{json}->encode($pipeline_data));
        
        my $response = $client_data->{ua}->request($request);

lib/DBD/libsql.pm  view on Meta::CPAN

=head1 DEPENDENCIES

This module requires the following Perl modules:

=over 4

=item * DBI (1.631 or later)

=item * LWP::UserAgent (6.00 or later)

=item * HTTP::Request (6.00 or later)

=item * JSON (4.00 or later)

=item * IO::Socket::SSL (2.00 or later) - for HTTPS connections

=back

=head1 AUTHOR

ytnobody E<lt>ytnobody@gmail.comE<gt>

lib/DBD/libsql/Hrana.pm  view on Meta::CPAN

package DBD::libsql::Hrana;
use strict;
use warnings;
use LWP::UserAgent;
use HTTP::Request;
use JSON;
use Protocol::WebSocket;
use IO::Socket::SSL;
use Carp;

our $VERSION = "0.06";

# Hrana Protocol Client for libSQL
# Based on the Hrana protocol specification used by libsql-client-ts

lib/DBD/libsql/Hrana.pm  view on Meta::CPAN

    
    my $request_body = {
        type => 'execute',
        stmt => {
            sql => $sql,
            args => $params || [],
        }
    };
    
    my $url = $self->{url} . '/v2/pipeline';
    my $request = HTTP::Request->new('POST', $url);
    $request->header('Content-Type' => 'application/json');
    
    if ($self->{auth_token}) {
        $request->header('Authorization' => 'Bearer ' . $self->{auth_token});
    }
    
    $request->content($self->{json}->encode({
        requests => [$request_body]
    }));
    

lib/DBD/libsql/Hrana.pm  view on Meta::CPAN

                type => 'execute', 
                stmt => {
                    sql => $stmt,
                    args => [],
                }
            };
        }
    }
    
    my $url = $self->{url} . '/v2/pipeline';
    my $request = HTTP::Request->new('POST', $url);
    $request->header('Content-Type' => 'application/json');
    
    if ($self->{auth_token}) {
        $request->header('Authorization' => 'Bearer ' . $self->{auth_token});
    }
    
    $request->content($self->{json}->encode({
        requests => \@requests
    }));
    

xt/01_integration.t  view on Meta::CPAN

    plan tests => 4;
    
    my $ua = LWP::UserAgent->new(timeout => 10);
    my $json = JSON->new->utf8;
    
    # Test health endpoint
    my $health_response = $ua->get('http://127.0.0.1:8080/health');
    ok($health_response->is_success, 'Health endpoint accessible');
    
    # Test Hrana pipeline endpoint
    my $request = HTTP::Request->new('POST', 'http://127.0.0.1:8080/v2/pipeline');
    $request->header('Content-Type' => 'application/json');
    
    my $pipeline_data = {
        requests => [
            {
                type => 'execute',
                stmt => {
                    sql => 'SELECT 1 as test_value',
                    args => []
                }



( run in 1.442 second using v1.01-cache-2.11-cpan-13bb782fe5a )