NAME

Net::Blossom::Server::Backend::SQLite - SQLite storage backend for Blossom servers

SYNOPSIS

use Net::Blossom::Server;
use Net::Blossom::Server::Backend::SQLite;

my $storage = Net::Blossom::Server::Backend::SQLite->new(
    database => '/var/lib/blossom/blossom.sqlite',
    base_url => 'https://cdn.example.com',
);
$storage->deploy_schema;

my $server = Net::Blossom::Server->new(storage => $storage);

DESCRIPTION

Net::Blossom::Server::Backend::SQLite is a SQLite storage backend for Net::Blossom::Server. It stores Blossom blob bytes and metadata in a SQLite database and implements the Net::Blossom::Server::Storage contract.

SQLite access is provided through DBI and DBD::SQLite.

This backend is intended for self-contained single-node deployments, local development, and tests. It can be a reasonable production choice when blob sizes, traffic, and write concurrency are controlled.

Blob bodies are stored in SQLite BLOB values. This keeps storage simple, but large media archives or high-traffic public servers should usually use Postgres or a backend that stores blob bytes outside the metadata database.

CONSTRUCTOR

new

my $storage = Net::Blossom::Server::Backend::SQLite->new(
    database => $path,
    base_url => $url,
);

Creates a storage object. database is the SQLite database file path. base_url is the public HTTP or HTTPS URL prefix used when descriptors are created. It may include a path prefix, but not userinfo, query, or fragment parts. Trailing slashes are removed.

Instead of database, callers may pass an existing DBI handle as dbh. The handle must be a SQLite handle.

METHODS

dbh

my $dbh = $storage->dbh;

Returns the DBI handle used by the backend.

base_url

my $url = $storage->base_url;

Returns the normalized descriptor URL prefix.

deploy_schema

$storage->deploy_schema;

Creates the required SQLite tables and indexes if they do not already exist. This method is safe to call more than once.

begin_upload

my $upload = $storage->begin_upload(%context);

Starts a blob upload and returns an upload writer. The server core writes bytes to the writer and later calls commit with validated blob metadata.

get_blob

my $result = $storage->get_blob($sha256);

Returns a Net::Blossom::Server::BlobResult for $sha256, or undef when the blob is absent.

head_blob

my $descriptor = $storage->head_blob($sha256);

Returns a Net::Blossom::BlobDescriptor without returning the blob body, or undef when the blob is absent.

delete_blob

my $deleted = $storage->delete_blob($sha256, pubkey => $pubkey);

Deletes one owner relationship when pubkey is supplied. The blob bytes are deleted when the final owner is removed. Without pubkey, the blob and all owners are deleted.

list_blobs

my $descriptors = $storage->list_blobs($pubkey, limit => 100);

Returns descriptors owned by $pubkey, sorted by uploaded descending and sha256 ascending. cursor and limit follow the Net::Blossom::Server::Storage contract.