> ## Documentation Index
> Fetch the complete documentation index at: https://easyaf.nimbleapps.cloud/llms.txt
> Use this file to discover all available pages before exploring further.

# TursoDatabase

> Base class for Turso databases. Inherit from this class and add              `TursoDbSet`1` properties for each entity type.

## Definition

**Assembly:** CloudNimble.BlazorEssentials.TursoDb.dll

**Namespace:** CloudNimble.BlazorEssentials.TursoDb

**Inheritance:** System.Object

## Syntax

```csharp theme={"dark"}
CloudNimble.BlazorEssentials.TursoDb.TursoDatabase
```

## Summary

Base class for Turso databases. Inherit from this class and add
`TursoDbSet`1\` properties for each entity type.

## Examples

```csharp theme={"dark"}
public class AppDatabase : TursoDatabase
{
    public TursoDbSet&lt;User&gt; Users { get; }
    public TursoDbSet&lt;Post&gt; Posts { get; }

    public AppDatabase(IJSRuntime jsRuntime) : base(jsRuntime)
    {
        Name = "app.db";
        Users = new TursoDbSet&lt;User&gt;(this);
        Posts = new TursoDbSet&lt;Post&gt;(this);
    }
}
```

## Constructors

### &#x20;.ctor Inherited

> [!NOTE]
>
> Inherited from `object`

#### Syntax

```csharp theme={"dark"}
public Object()
```

## Properties

### &#x20;AuthToken

Gets or sets the authentication token for remote Turso databases.

#### Syntax

```csharp theme={"dark"}
public string AuthToken { get; set; }
```

#### Property Value

Type: `string?`

### &#x20;AutoCreateSchema

Gets or sets whether to automatically create tables on connect.

#### Syntax

```csharp theme={"dark"}
public bool AutoCreateSchema { get; set; }
```

#### Property Value

Type: `bool`

### &#x20;DbSets

Gets the list of DbSets in this database.

#### Syntax

```csharp theme={"dark"}
public System.Collections.Generic.List<CloudNimble.BlazorEssentials.TursoDb.ITursoDbSet> DbSets { get; }
```

#### Property Value

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

### &#x20;IsConnected

Gets whether the database is currently connected.

#### Syntax

```csharp theme={"dark"}
public bool IsConnected { get; }
```

#### Property Value

Type: `bool`

### &#x20;Name

Gets or sets the database name/identifier.
This is used as the connection key in JavaScript.

#### Syntax

```csharp theme={"dark"}
public string Name { get; init; }
```

#### Property Value

Type: `string`

### &#x20;Url

Gets or sets the database URL.
Use ":memory:" for in-memory, "file:name.db" for local file, or a Turso cloud URL.

#### Syntax

```csharp theme={"dark"}
public string Url { get; set; }
```

#### Property Value

Type: `string`

## Methods

### &#x20;BeginTransactionAsync

Begins a new database transaction.

#### Syntax

```csharp theme={"dark"}
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

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

### &#x20;ConnectAsync

Connects to the database.

#### Syntax

```csharp theme={"dark"}
public System.Threading.Tasks.Task ConnectAsync()
```

#### Returns

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

### &#x20;DisconnectAsync

Disconnects from the database.

#### Syntax

```csharp theme={"dark"}
public System.Threading.Tasks.Task DisconnectAsync()
```

#### Returns

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

### &#x20;DisposeAsync

#### Syntax

```csharp theme={"dark"}
public System.Threading.Tasks.ValueTask DisposeAsync()
```

#### Returns

Type: `System.Threading.Tasks.ValueTask`

### &#x20;EnsureConnectedAsync

Ensures the database is connected, connecting if necessary.

#### Syntax

```csharp theme={"dark"}
public System.Threading.Tasks.Task EnsureConnectedAsync()
```

#### Returns

Type: `System.Threading.Tasks.Task`

### &#x20;Equals Inherited Virtual

> [!NOTE]
>
> Inherited from `object`

#### Syntax

```csharp theme={"dark"}
public virtual bool Equals(object obj)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `obj` | `object?` | - |

#### Returns

Type: `bool`

### &#x20;Equals Inherited

> [!NOTE]
>
> Inherited from `object`

#### Syntax

```csharp theme={"dark"}
public static bool Equals(object objA, object objB)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `objA` | `object?` | - |
| `objB` | `object?` | - |

#### Returns

Type: `bool`

### &#x20;ExecuteAsync

Executes a SQL statement and returns the result.

#### Syntax

```csharp theme={"dark"}
public System.Threading.Tasks.Task<CloudNimble.BlazorEssentials.TursoDb.TursoResult> ExecuteAsync(string sql, params object[] parameters)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `sql` | `string` | The SQL statement to execute. |
| `parameters` | `object?[]` | The parameters for the SQL statement. |

#### Returns

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

### &#x20;ExecuteBatchAsync

Executes multiple SQL statements in a batch.

#### Syntax

```csharp theme={"dark"}
public System.Threading.Tasks.Task<System.Collections.Generic.List<CloudNimble.BlazorEssentials.TursoDb.TursoResult>> ExecuteBatchAsync(params (string, object[])[] statements)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `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.

### &#x20;GetHashCode Inherited Virtual

> [!NOTE]
>
> Inherited from `object`

#### Syntax

```csharp theme={"dark"}
public virtual int GetHashCode()
```

#### Returns

Type: `int`

### &#x20;GetType Inherited

> [!NOTE]
>
> Inherited from `object`

#### Syntax

```csharp theme={"dark"}
public System.Type GetType()
```

#### Returns

Type: `System.Type`

### &#x20;MemberwiseClone Inherited

> [!NOTE]
>
> Inherited from `object`

#### Syntax

```csharp theme={"dark"}
protected internal object MemberwiseClone()
```

#### Returns

Type: `object`

### &#x20;Prepare

Creates a prepared statement for queries that return results.

#### Syntax

```csharp theme={"dark"}
public CloudNimble.BlazorEssentials.TursoDb.TursoPreparedStatement<TResult> Prepare<TResult>(string sql) where TResult : class, new()
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `sql` | `string` | The 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.

### &#x20;Prepare

Creates a prepared statement for non-query commands.

#### Syntax

```csharp theme={"dark"}
public CloudNimble.BlazorEssentials.TursoDb.TursoPreparedStatement Prepare(string sql)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `sql` | `string` | The SQL command to prepare. |

#### Returns

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

### &#x20;QueryAsync

Executes a SQL query and returns all matching rows.

#### Syntax

```csharp theme={"dark"}
public System.Threading.Tasks.Task<System.Collections.Generic.List<T>> QueryAsync<T>(string sql, params object[] parameters)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `sql` | `string` | The SQL query to execute. |
| `parameters` | `object?[]` | 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.

### &#x20;QuerySingleAsync

Executes a SQL query and returns the first matching row or null.

#### Syntax

```csharp theme={"dark"}
public System.Threading.Tasks.Task<T> QuerySingleAsync<T>(string sql, params object[] parameters)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `sql` | `string` | The SQL query to execute. |
| `parameters` | `object?[]` | 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.

### &#x20;ReferenceEquals Inherited

> [!NOTE]
>
> Inherited from `object`

#### Syntax

```csharp theme={"dark"}
public static bool ReferenceEquals(object objA, object objB)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `objA` | `object?` | - |
| `objB` | `object?` | - |

#### Returns

Type: `bool`

### &#x20;ToString Inherited Virtual

> [!NOTE]
>
> Inherited from `object`

#### Syntax

```csharp theme={"dark"}
public virtual string ToString()
```

#### Returns

Type: `string?`

## Related APIs

* System.IAsyncDisposable


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.