Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A .NET client for libsql

License

NotificationsYou must be signed in to change notification settings

tvandinther/libsql-client-dotnet

Repository files navigation

tests

Libsql.Client

A .NET client library for libsql.

This project is still in early development and not ready for production use.

Currently Supported Features

  • Creating a database:
    • In memory.
    • From file.
    • From connection string.
  • Executing SQL statements:
    • Non-parameterised.

Planned Features

  • Positional and named arguments.
  • Embedded replicas.
  • Prepared statements.
  • Batched statements.
  • Transactions.

Usage

For an example, see the Demo project in the repository.

Creating a Database

You can open a database in different locations:

  1. In-Memory Database
// Create an in-memory database.vardbClient=awaitDatabaseClient.Create(opts=>{opts.Url=":memory:";});
  1. From a File
// Creates or opens a database stored in a local file.vardbClient=awaitDatabaseClient.Create(opts=>{opts.Url="file:./mydb.sqlite";});
  1. From a Connection String
// Opens a database using a full connection string.vardbClient=awaitDatabaseClient.Create(opts=>{opts.Url="https://my-remote-db.example.com";});

Provide Additional Connection Options

Remote Databases

For remote libSQL databases, use client options for authentication and secure connections:

// Connect to a remote database with authentication and HTTPS enabledvardbClient=awaitDatabaseClient.Create(opts=>{opts.Url="https://my-remote-db.example.com";opts.AuthToken="MY_TOKEN";opts.UseHttps=true;});

Local File Databases

For local files, you can pass standard query parameters via the file URI:

// Open a local database with query parametersvardbClient=awaitDatabaseClient.Create(opts=>{opts.Url="file:mydb.sqlite?mode=rwc&cache=shared";});

Executing SQL Statements

Using direct queries

awaitdbClient.Execute("CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT, height REAL)");

Using positional arguments

awaitdbClient.Execute("SELECT name FROM users WHERE id = ?",userId);

Querying the Database

UserToUser(IEnumerable<Value>row){varrowArray=row.ToArray();if(rowArray[0]isInteger{Value:varid}&&rowArray[1]isText{Value:varname}&&rowArray[2]isReal{Value:varheight}{returnnewUser(id,name,height);}thrownewArgumentException();}varresult=awaitdbClient.Execute("SELECT * FROM users");varusers=result.Rows.Select(ToUser);

Closing the Database

dbClient.Dispose();

or with ausing statement:

using(vardbClient=awaitDatabaseClient.Create(opts=>{opts.Url=":memory:";})){// ...}

Disclaimer

This project is still in early development and not ready for production use. The API is subject to include breaking changes on minor versions until version 1.0.

The full test suite is run only on a Linux x64 platform. Most of the test suite is run on Linux, Windows, and macOS x64 platforms. The test suite runs on .NET 7.

Progress

  • A database can be created:
    • In memory.
    • From file.
    • From connection string.
  • A database can be destroyed/closed/deallocated.
  • An embedded replica can be created.
    • An embeded replica can be synced.
  • The database can execute SQL statements:
    • Non-parameterised.
    • Parameterised with positional arguments.
    • Parameterised with named arguments.
  • Prepared statements.
  • Batched statements.
  • Transactions.
  • A result set is returned from an execution.
    • With the column names.
    • With an enumerable of enumerable (rows) of typed boxed values.
    • With the number of affected rows.
    • With the last inserted row id.

[8]ページ先頭

©2009-2025 Movatter.jp