# DuckDBResourceBuilderExtensions Methods

- Package: [CommunityToolkit.Aspire.Hosting.DuckDB](/reference/api/csharp/communitytoolkit.aspire.hosting.duckdb.md)
- Type: [DuckDBResourceBuilderExtensions](/reference/api/csharp/communitytoolkit.aspire.hosting.duckdb/duckdbresourcebuilderextensions.md)
- Kind: `Methods`
- Members: `2`

Provides extension methods for adding DuckDB resources to an application builder.

<a id="addduckdb"></a>
<a id="addduckdb-idistributedapplicationbuilder-string-string-string"></a>

## AddDuckDB(IDistributedApplicationBuilder, string, string?, string?)

- Name: `AddDuckDB(IDistributedApplicationBuilder, string, string?, string?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<DuckDBResource>`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d479e13473b1d29d06b974f144a0049289a3cb5c/src/CommunityToolkit.Aspire.Hosting.DuckDB/DuckDBResourceBuilderExtensions.cs#L23-L56)

Adds a DuckDB resource to the application builder.

```csharp
public static class DuckDBResourceBuilderExtensions
{
    public static IResourceBuilder<DuckDBResource> AddDuckDB(
        this IDistributedApplicationBuilder builder,
        string name,
        string? databasePath = null,
        string? databaseFileName = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IDistributedApplicationBuilder`)
  The application builder.
- `name` (`string`)
  The name of the resource.
- `databasePath` (`string?`) `optional`
  The optional path to the database file. If no path is provided the database is stored in a temporary location.
- `databaseFileName` (`string?`) `optional`
  The filename of the database file. Must include extension. If no file name is provided, a randomly generated file name is used.

## Returns

`IResourceBuilder<DuckDBResource>` -- A resource builder for the DuckDB resource.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

<a id="withreadonly"></a>
<a id="withreadonly-iresourcebuilder-duckdbresource"></a>

## WithReadOnly(IResourceBuilder<DuckDBResource>)

- Name: `WithReadOnly(IResourceBuilder<DuckDBResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<DuckDBResource>`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d479e13473b1d29d06b974f144a0049289a3cb5c/src/CommunityToolkit.Aspire.Hosting.DuckDB/DuckDBResourceBuilderExtensions.cs#L67-L71)

Configures the DuckDB resource to open the database in read-only mode.

```csharp
public static class DuckDBResourceBuilderExtensions
{
    public static IResourceBuilder<DuckDBResource> WithReadOnly(
        this IResourceBuilder<DuckDBResource> builder)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<DuckDBResource>`)
  The resource builder.

## Returns

`IResourceBuilder<DuckDBResource>` -- A resource builder for the DuckDB resource.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.
