Skip to main content

Definition

Assembly: CloudNimble.BlazorEssentials.TursoDb.dll Namespace: CloudNimble.BlazorEssentials.TursoDb Inheritance: CloudNimble.BlazorEssentials.TursoDb.TursoDatabase

Syntax

CloudNimble.BlazorEssentials.TursoDb.TursoSyncDatabase

Summary

Base class for sync-enabled Turso databases. Extends TursoDatabase with Turso Cloud synchronization capabilities (pull, push, sync).

Examples

public class AppDatabase : TursoSyncDatabase
{
    public TursoDbSet<User> Users { get; }

    public AppDatabase(IJSRuntime jsRuntime) : base(jsRuntime)
    {
        Name = "app.db";
        SyncUrl = "libsql://mydb-myorg.turso.io";
        SyncAuthToken = "your-auth-token";
        Users = new TursoDbSet<User>(this);
    }
}

// Usage
await Database.ConnectAsync();
await Database.PullAsync();   // Pull changes from cloud
// ... make local changes ...
await Database.PushAsync();   // Push local changes to cloud

Constructors

.ctor Inherited

Inherited from CloudNimble.BlazorEssentials.TursoDb.TursoDatabase
Initializes a new instance of the TursoDatabase class.

Syntax

protected TursoDatabase(Microsoft.JSInterop.IJSRuntime jsRuntime)

Parameters

NameTypeDescription
jsRuntimeMicrosoft.JSInterop.IJSRuntimeThe JavaScript runtime for interop.

Exceptions

ExceptionDescription
ArgumentNullExceptionThrown when jsRuntime is null.

.ctor Inherited

Inherited from object

Syntax

public Object()

Properties

AuthToken Inherited

Inherited from CloudNimble.BlazorEssentials.TursoDb.TursoDatabase
Gets or sets the authentication token for remote Turso databases.

Syntax

public string AuthToken { get; set; }

Property Value

Type: string?

AutoCreateSchema Inherited

Inherited from CloudNimble.BlazorEssentials.TursoDb.TursoDatabase
Gets or sets whether to automatically create tables on connect.

Syntax

public bool AutoCreateSchema { get; set; }

Property Value

Type: bool

DbSets Inherited

Inherited from CloudNimble.BlazorEssentials.TursoDb.TursoDatabase
Gets the list of DbSets in this database.

Syntax

public System.Collections.Generic.List<CloudNimble.BlazorEssentials.TursoDb.ITursoDbSet> DbSets { get; }

Property Value

Type: System.Collections.Generic.List<CloudNimble.BlazorEssentials.TursoDb.ITursoDbSet>

EncryptionEnabled

Gets or sets whether encryption is enabled for the local database.

Syntax

public bool EncryptionEnabled { get; set; }

Property Value

Type: bool

EncryptionKey

Gets or sets the encryption key for the local database.

Syntax

public string EncryptionKey { get; set; }

Property Value

Type: string?

IsConnected Inherited

Inherited from CloudNimble.BlazorEssentials.TursoDb.TursoDatabase
Gets whether the database is currently connected.

Syntax

public bool IsConnected { get; }

Property Value

Type: bool

IsSyncing

Gets whether a sync operation is currently in progress.

Syntax

public bool IsSyncing { get; }

Property Value

Type: bool

Name Inherited

Inherited from CloudNimble.BlazorEssentials.TursoDb.TursoDatabase
Gets or sets the database name/identifier. This is used as the connection key in JavaScript.

Syntax

public string Name { get; init; }

Property Value

Type: string

SyncAuthToken

Gets or sets the authentication token for Turso Cloud sync.

Syntax

public string SyncAuthToken { get; set; }

Property Value

Type: string

SyncIntervalMs

Gets or sets the sync interval in milliseconds. Set to 0 to disable automatic periodic sync. Default is 0.

Syntax

public int SyncIntervalMs { get; set; }

Property Value

Type: int

SyncOnConnect

Gets or sets whether to sync on connect. Default is true.

Syntax

public bool SyncOnConnect { get; set; }

Property Value

Type: bool

SyncUrl

Gets or sets the sync URL for Turso Cloud. This is typically in the format: libsql://[database-name]-[org-name].turso.io

Syntax

public string SyncUrl { get; set; }

Property Value

Type: string

Url Inherited

Inherited from CloudNimble.BlazorEssentials.TursoDb.TursoDatabase
Gets or sets the database URL. Use “:memory:” for in-memory, “file:name.db” for local file, or a Turso cloud URL.

Syntax

public string Url { get; set; }

Property Value

Type: string

Methods

BeginTransactionAsync Inherited

Inherited from CloudNimble.BlazorEssentials.TursoDb.TursoDatabase
Begins a new database transaction.

Syntax

public System.Threading.Tasks.Task<CloudNimble.BlazorEssentials.TursoDb.TursoTransaction> BeginTransactionAsync()

Returns

Type: System.Threading.Tasks.Task<CloudNimble.BlazorEssentials.TursoDb.TursoTransaction> A transaction that can be committed or rolled back.

Examples

await using var transaction = await Database.BeginTransactionAsync();
try
{
    await Database.Users.AddAsync(user);
    await transaction.CommitAsync();
}
catch
{
    await transaction.RollbackAsync();
    throw;
}

CallJavaScriptAsync Inherited

Inherited from CloudNimble.BlazorEssentials.TursoDb.TursoDatabase
Calls a JavaScript function in the Turso module.

Syntax

internal System.Threading.Tasks.Task CallJavaScriptAsync(string functionName, params object[] args)

Parameters

NameTypeDescription
functionNamestring-
argsobject?[]-

Returns

Type: System.Threading.Tasks.Task

CallJavaScriptAsync Inherited

Inherited from CloudNimble.BlazorEssentials.TursoDb.TursoDatabase
Calls a JavaScript function in the Turso module and returns the result.

Syntax

internal System.Threading.Tasks.Task<TResult> CallJavaScriptAsync<TResult>(string functionName, params object[] args)

Parameters

NameTypeDescription
functionNamestring-
argsobject?[]-

Returns

Type: System.Threading.Tasks.Task<TResult>

ConnectAsync

Connects to the database with sync support. If TursoSyncDatabase.SyncOnConnect is true, performs an initial sync after connecting.

Syntax

public System.Threading.Tasks.Task ConnectAsync()

Returns

Type: System.Threading.Tasks.Task

ConnectAsync Inherited

Inherited from CloudNimble.BlazorEssentials.TursoDb.TursoDatabase
Connects to the database.

Syntax

public System.Threading.Tasks.Task ConnectAsync()

Returns

Type: System.Threading.Tasks.Task A task representing the asynchronous operation.

DisconnectAsync Inherited

Inherited from CloudNimble.BlazorEssentials.TursoDb.TursoDatabase
Disconnects from the database.

Syntax

public System.Threading.Tasks.Task DisconnectAsync()

Returns

Type: System.Threading.Tasks.Task A task representing the asynchronous operation.

DisposeAsync Inherited

Inherited from CloudNimble.BlazorEssentials.TursoDb.TursoDatabase

Syntax

public System.Threading.Tasks.ValueTask DisposeAsync()

Returns

Type: System.Threading.Tasks.ValueTask

EnsureConnectedAsync Inherited

Inherited from CloudNimble.BlazorEssentials.TursoDb.TursoDatabase
Ensures the database is connected, connecting if necessary.

Syntax

public System.Threading.Tasks.Task EnsureConnectedAsync()

Returns

Type: System.Threading.Tasks.Task

Equals Inherited Virtual

Inherited from object

Syntax

public virtual bool Equals(object obj)

Parameters

NameTypeDescription
objobject?-

Returns

Type: bool

Equals Inherited

Inherited from object

Syntax

public static bool Equals(object objA, object objB)

Parameters

NameTypeDescription
objAobject?-
objBobject?-

Returns

Type: bool

ExecuteAsync Inherited

Inherited from CloudNimble.BlazorEssentials.TursoDb.TursoDatabase
Executes a SQL statement and returns the result.

Syntax

public System.Threading.Tasks.Task<CloudNimble.BlazorEssentials.TursoDb.TursoResult> ExecuteAsync(string sql, params object[] parameters)

Parameters

NameTypeDescription
sqlstringThe SQL statement to execute.
parametersobject?[]The parameters for the SQL statement.

Returns

Type: System.Threading.Tasks.Task<CloudNimble.BlazorEssentials.TursoDb.TursoResult> The execution result.

ExecuteBatchAsync Inherited

Inherited from CloudNimble.BlazorEssentials.TursoDb.TursoDatabase
Executes multiple SQL statements in a batch.

Syntax

public System.Threading.Tasks.Task<System.Collections.Generic.List<CloudNimble.BlazorEssentials.TursoDb.TursoResult>> ExecuteBatchAsync(params (string, object[])[] statements)

Parameters

NameTypeDescription
statements(string, object?[])[]The statements to execute.

Returns

Type: System.Threading.Tasks.Task<System.Collections.Generic.List<CloudNimble.BlazorEssentials.TursoDb.TursoResult>> The results of each statement.

GetHashCode Inherited Virtual

Inherited from object

Syntax

public virtual int GetHashCode()

Returns

Type: int

GetType Inherited

Inherited from object

Syntax

public System.Type GetType()

Returns

Type: System.Type

MemberwiseClone Inherited

Inherited from object

Syntax

protected internal object MemberwiseClone()

Returns

Type: object

Prepare Inherited

Inherited from CloudNimble.BlazorEssentials.TursoDb.TursoDatabase
Creates a prepared statement for queries that return results.

Syntax

public CloudNimble.BlazorEssentials.TursoDb.TursoPreparedStatement<TResult> Prepare<TResult>(string sql) where TResult : class, new()

Parameters

NameTypeDescription
sqlstringThe SQL query to prepare.

Returns

Type: CloudNimble.BlazorEssentials.TursoDb.TursoPreparedStatement<TResult> A prepared statement that can be executed multiple times.

Type Parameters

  • TResult - The type of result returned by the query.

Prepare Inherited

Inherited from CloudNimble.BlazorEssentials.TursoDb.TursoDatabase
Creates a prepared statement for non-query commands.

Syntax

public CloudNimble.BlazorEssentials.TursoDb.TursoPreparedStatement Prepare(string sql)

Parameters

NameTypeDescription
sqlstringThe SQL command to prepare.

Returns

Type: CloudNimble.BlazorEssentials.TursoDb.TursoPreparedStatement A prepared statement that can be executed multiple times.

PullAsync

Pulls changes from Turso Cloud to the local database. This downloads any changes made on other devices or the cloud.

Syntax

public System.Threading.Tasks.Task<CloudNimble.BlazorEssentials.TursoDb.TursoSyncResult> PullAsync()

Returns

Type: System.Threading.Tasks.Task<CloudNimble.BlazorEssentials.TursoDb.TursoSyncResult> The sync result containing the number of frames synced.

PushAsync

Pushes local changes to Turso Cloud. This uploads any local changes to the cloud for other devices to sync.

Syntax

public System.Threading.Tasks.Task<CloudNimble.BlazorEssentials.TursoDb.TursoSyncResult> PushAsync()

Returns

Type: System.Threading.Tasks.Task<CloudNimble.BlazorEssentials.TursoDb.TursoSyncResult> The sync result containing the number of frames synced.

QueryAsync Inherited

Inherited from CloudNimble.BlazorEssentials.TursoDb.TursoDatabase
Executes a SQL query and returns all matching rows.

Syntax

public System.Threading.Tasks.Task<System.Collections.Generic.List<T>> QueryAsync<T>(string sql, params object[] parameters)

Parameters

NameTypeDescription
sqlstringThe SQL query to execute.
parametersobject?[]The parameters for the SQL query.

Returns

Type: System.Threading.Tasks.Task<System.Collections.Generic.List<T>> A list of results.

Type Parameters

  • T - The type to deserialize results into.

QuerySingleAsync Inherited

Inherited from CloudNimble.BlazorEssentials.TursoDb.TursoDatabase
Executes a SQL query and returns the first matching row or null.

Syntax

public System.Threading.Tasks.Task<T> QuerySingleAsync<T>(string sql, params object[] parameters)

Parameters

NameTypeDescription
sqlstringThe SQL query to execute.
parametersobject?[]The parameters for the SQL query.

Returns

Type: System.Threading.Tasks.Task<T?> The first result or default.

Type Parameters

  • T - The type to deserialize the result into.

ReferenceEquals Inherited

Inherited from object

Syntax

public static bool ReferenceEquals(object objA, object objB)

Parameters

NameTypeDescription
objAobject?-
objBobject?-

Returns

Type: bool

SyncAsync

Performs a bidirectional sync with Turso Cloud. This combines pull and push operations.

Syntax

public System.Threading.Tasks.Task<CloudNimble.BlazorEssentials.TursoDb.TursoSyncResult> SyncAsync()

Returns

Type: System.Threading.Tasks.Task<CloudNimble.BlazorEssentials.TursoDb.TursoSyncResult> The sync result containing the number of frames synced.

ToString Inherited Virtual

Inherited from object

Syntax

public virtual string ToString()

Returns

Type: string?

Events

SyncCompleted

Occurs when a sync operation completes successfully.

Syntax

public System.EventHandler<CloudNimble.BlazorEssentials.TursoDb.TursoSyncResult> SyncCompleted

SyncFailed

Occurs when a sync operation fails.

Syntax

public System.EventHandler<System.Exception> SyncFailed

SyncStarted

Occurs when a sync operation starts.

Syntax

public System.EventHandler SyncStarted
  • System.IAsyncDisposable