Getting Started with Databases
This guide walks you through setting up your first database connection in Ductape, from installation to executing your first query.
Prerequisites
Before you begin, make sure you have:
- A Ductape account and workspace
- A product created in your workspace
- Access to a database (PostgreSQL, MySQL, MongoDB, or DynamoDB)
- The Ductape SDK installed in your project
Step 1: Install the SDK
Install the Ductape SDK:
- TypeScript
- Java
- Go
- .NET
npm install @ductape/sdk@0.1.8
<dependency>
<groupId>app.ductape</groupId>
<artifactId>sdk</artifactId>
<version>0.1.8</version>
</dependency>
go get github.com/ductape/ductape/sdk/go@v0.1.8
dotnet add package Ductape.Sdk --version 0.1.8
The SDK includes all database drivers (PostgreSQL, MySQL, MongoDB, DynamoDB) out of the box.
Step 2: Initialize the SDK
Set up the Ductape SDK with your credentials. Set product and env on the constructor (runtime defaults):
- TypeScript
- Java
- Go
- .NET
import Ductape from '@ductape/sdk';
const ductape = new Ductape({
accessKey: 'your-access-key',
});
import app.ductape.sdk.Ductape;
import app.ductape.sdk.core.EnvType;
import app.ductape.sdk.core.RequestContext;
RequestContext auth = new RequestContext(null, null, null, null, 'your-access-key');
Ductape ductape = new Ductape(EnvType.PRODUCTION, auth);
import (
"context"
"github.com/ductape/ductape/sdk/go/core"
ductapesdk "github.com/ductape/ductape/sdk/go/ductape"
)
auth := core.NewRequestContext("", "", "", "", 'your-access-key')
client, err := ductapesdk.New(core.EnvProduction, auth)
if err != nil {
return err
}
using Ductape.Sdk;
using Ductape.Sdk.Core;
var auth = new RequestContext(null, null, null, null, 'your-access-key', null);
var ductape = new Ductape(EnvType.Production, auth);
Step 3: Register a Database
Register your database with environment-specific connection strings:
- TypeScript
- Java
- Go
- .NET
await ductape.databases.create({
product_tag: 'my-app',
name: 'User Database',
tag: 'users-db',
type: 'postgresql',
description: 'Stores user accounts and profiles',
envs: [
{
slug: 'dev',
connection_url: 'postgresql://localhost:5432/myapp_dev',
},
{
slug: 'stg',
connection_url: 'postgresql://staging-host:5432/myapp_staging',
},
{
slug: 'prd',
connection_url: 'postgresql://prod-host:5432/myapp_prod',
},
],
});
ductape.databases.create(Map.of(
"product_tag", "my-app",
"name", "User Database",
"tag", "users-db",
"type", "postgresql",
"description", "Stores user accounts and profiles",
envs: [
Map.of(
"slug", "dev",
"connection_url", "postgresql://"localhost", 5432/myapp_dev"
),
Map.of(
"slug", "stg",
"connection_url", "postgresql://staging-"host", 5432/myapp_staging"
),
Map.of(
"slug", "prd",
"connection_url", "postgresql://prod-"host", 5432/myapp_prod"
),
]
));
client.databases.create({
"product_tag": "my-app",
"name": "User Database",
"tag": "users-db",
"type": "postgresql",
"description": "Stores user accounts and profiles",
envs: [
{
"slug": "dev",
"connection_url": "postgresql://"localhost": 5432/myapp_dev",
},
{
"slug": "stg",
"connection_url": "postgresql://staging-"host": 5432/myapp_staging",
},
{
"slug": "prd",
"connection_url": "postgresql://prod-"host": 5432/myapp_prod",
},
],
});
await ductape.databases.create({
["product_tag"] = "my-app",
["name"] = "User Database",
["tag"] = "users-db",
["type"] = "postgresql",
["description"] = "Stores user accounts and profiles",
envs: [
{
["slug"] = "dev",
["connection_url"] = "postgresql://["localhost"] = 5432/myapp_dev",
},
{
["slug"] = "stg",
["connection_url"] = "postgresql://staging-["host"] = 5432/myapp_staging",
},
{
["slug"] = "prd",
["connection_url"] = "postgresql://prod-["host"] = 5432/myapp_prod",
},
],
});
You can also link a managed PostgreSQL instance from a workspace cloud account by tag — Ductape imports or provisions the instance and stores the connection URL as a secret.
Check available tiers before provisioning to control cost:
- TypeScript
- Java
- Go
- .NET
const tiers = await ductape.cloud.tiers.list({ provider: 'aws', resource_type: 'database', db_type: 'postgresql' });
// tiers[0].tiers → [{ name: 'db.t3.micro', label: 'Micro — 2 vCPU, 1 GB', est_cost_per_month: 11.68, free_tier: true }, …]
Map<String, Object> tiers = ductape.cloud.tiers.list(Map.of( "provider", "aws", "resource_type", "database", "db_type", "postgresql" ));
// tiers[0].tiers → [Map.of( "name", "db.t3.micro", "label", "Micro — 2 vCPU, 1 GB", "est_cost_per_month", 11.68, "free_tier", true ), …]
tiers := client.cloud.tiers.list({ "provider": "aws", "resource_type": "database", "db_type": "postgresql" });
// tiers[0].tiers → [{ "name": "db.t3.micro", "label": "Micro — 2 vCPU, 1 GB", "est_cost_per_month": 11.68, "free_tier": true }, …]
var tiers = await ductape.cloud.tiers.list({ ["provider"] = "aws", ["resource_type"] = "database", ["db_type"] = "postgresql" });
// tiers[0].tiers → [{ ["name"] = "db.t3.micro", ["label"] = "Micro — 2 vCPU, 1 GB", ["est_cost_per_month"] = 11.68, ["free_tier"] = true }, …]
AWS RDS:
- TypeScript
- Java
- Go
- .NET
await ductape.databases.create({
product: 'my-app',
name: 'User Database',
tag: 'users-db',
type: 'postgresql',
envs: [{
slug: 'prd',
cloud: 'prod_aws',
instance: 'my-rds-instance',
tier: 'db.t3.micro', // from cloud.tiers.list()
region: 'us-east-1',
}],
});
ductape.databases.create(Map.of(
"product", "my-app",
"name", "User Database",
"tag", "users-db",
"type", "postgresql",
envs: [Map.of(
"slug", "prd",
"cloud", "prod_aws",
"instance", "my-rds-instance",
"tier", "db.t3.micro", // from cloud.tiers.list()
"region", "us-east-1"
)]
));
client.databases.create({
"product": "my-app",
"name": "User Database",
"tag": "users-db",
"type": "postgresql",
envs: [{
"slug": "prd",
"cloud": "prod_aws",
"instance": "my-rds-instance",
"tier": "db.t3.micro", // from cloud.tiers.list()
"region": "us-east-1",
}],
});
await ductape.databases.create({
["product"] = "my-app",
["name"] = "User Database",
["tag"] = "users-db",
["type"] = "postgresql",
envs: [{
["slug"] = "prd",
["cloud"] = "prod_aws",
["instance"] = "my-rds-instance",
["tier"] = "db.t3.micro", // from cloud.tiers.list()
["region"] = "us-east-1",
}],
});
GCP Cloud SQL (PostgreSQL):
- TypeScript
- Java
- Go
- .NET
await ductape.databases.create({
product: 'my-app',
name: 'User Database',
tag: 'users-db',
type: 'postgresql',
envs: [{
slug: 'prd',
cloud: 'gcp_prod',
instance: 'my-cloudsql-instance',
tier: 'db-n1-standard-2',
region: 'us-central1',
}],
});
ductape.databases.create(Map.of(
"product", "my-app",
"name", "User Database",
"tag", "users-db",
"type", "postgresql",
envs: [Map.of(
"slug", "prd",
"cloud", "gcp_prod",
"instance", "my-cloudsql-instance",
"tier", "db-n1-standard-2",
"region", "us-central1"
)]
));
client.databases.create({
"product": "my-app",
"name": "User Database",
"tag": "users-db",
"type": "postgresql",
envs: [{
"slug": "prd",
"cloud": "gcp_prod",
"instance": "my-cloudsql-instance",
"tier": "db-n1-standard-2",
"region": "us-central1",
}],
});
await ductape.databases.create({
["product"] = "my-app",
["name"] = "User Database",
["tag"] = "users-db",
["type"] = "postgresql",
envs: [{
["slug"] = "prd",
["cloud"] = "gcp_prod",
["instance"] = "my-cloudsql-instance",
["tier"] = "db-n1-standard-2",
["region"] = "us-central1",
}],
});
Azure PostgreSQL Flexible Server:
- TypeScript
- Java
- Go
- .NET
await ductape.databases.create({
product: 'my-app',
name: 'User Database',
tag: 'users-db',
type: 'postgresql',
envs: [{
slug: 'prd',
cloud: 'prod_azure',
instance: 'my-pg-server',
tier: 'Standard_B1ms',
region: 'eastus',
}],
});
ductape.databases.create(Map.of(
"product", "my-app",
"name", "User Database",
"tag", "users-db",
"type", "postgresql",
envs: [Map.of(
"slug", "prd",
"cloud", "prod_azure",
"instance", "my-pg-server",
"tier", "Standard_B1ms",
"region", "eastus"
)]
));
client.databases.create({
"product": "my-app",
"name": "User Database",
"tag": "users-db",
"type": "postgresql",
envs: [{
"slug": "prd",
"cloud": "prod_azure",
"instance": "my-pg-server",
"tier": "Standard_B1ms",
"region": "eastus",
}],
});
await ductape.databases.create({
["product"] = "my-app",
["name"] = "User Database",
["tag"] = "users-db",
["type"] = "postgresql",
envs: [{
["slug"] = "prd",
["cloud"] = "prod_azure",
["instance"] = "my-pg-server",
["tier"] = "Standard_B1ms",
["region"] = "eastus",
}],
});
See Cloud-linked components for the full AWS / GCP / Azure matrix, tier reference, and setup steps.
Database Configuration Fields
| Field | Type | Required | Description |
|---|---|---|---|
product_tag | string | Yes | Product identifier to associate the database with |
name | string | Yes | Human-readable display name |
tag | string | Yes | Unique identifier for the database |
type | string | Yes | Database type: postgresql, mysql, mongodb, or dynamodb |
description | string | No | Description of what the database stores |
envs | array | Yes | Environment-specific connection configurations |
Environment Configuration
| Field | Type | Required | Description |
|---|---|---|---|
slug | string | Yes | Environment identifier (e.g., dev, staging, prd) |
connection_url | string | Yes | Database connection string |
description | string | No | Environment-specific notes |
Step 4: Connect to Your Database
Before running queries, establish a connection:
- TypeScript
- Java
- Go
- .NET
const result = await ductape.databases.connect({
database: 'users-db',
});
Map<String, Object> result = ductape.databases().connect(Map<String, Object>.of(
"database", "users-db"
));
import "context"
result := client.Databases.Connect(ctx, map[string]any{
"database": "users-db",
});
var result = await ductape.Database.Connect(new Dictionary<string, object?>
{
["database"] = "users-db",
});
console.log('Connected:', result.connected); console.log('Database Version:', result.version); console.log('Latency:', result.latency, 'ms');
Once connected, subsequent operations inherit the connection context. You no longer need to specify `env`, `product`, or `database` on every query (constructor defaults apply before connect; connection context applies after).
## Step 5: Run Your First Query
With the connection established, you can query your database:
```ts
// Query all active users
const result = await ductape.databases.find({
table: 'users',
where: { status: 'active' },
limit: 10,
});
console.log('Found users:', result.records);
console.log('Total count:', result.count);
Step 6: Insert Data
Add new records to your database:
- TypeScript
- Java
- Go
- .NET
const result = await ductape.databases.insert({
table: 'users',
records: [{
name: 'Jane Doe',
email: 'jane@example.com',
status: 'active',
created_at: new Date(),
}],
returning: true,
});
console.log('Inserted user ID:', result.insertedIds[0]);
console.log('Inserted data:', result.records);
Map<String, Object> result = ductape.databases().insert(Map<String, Object>.of(
"table", "users",
records: [Map.of(
"name", "Jane Doe",
"email", "jane@example.com",
"status", "active",
created_at: Instant.now()
)],
"returning", true
));
System.out.println('Inserted user "ID", ", result.insertedIds[0]);
System.out.println("Inserted data:', result.records);
import "context"
result := client.Databases.Insert(ctx, map[string]any{
"table": "users",
records: [{
"name": "Jane Doe",
"email": "jane@example.com",
"status": "active",
created_at: new Date(),
}],
"returning": true,
});
fmt.Println('Inserted user "ID": ", result.insertedIds[0]);
fmt.Println("Inserted data:', result.records);
var result = await ductape.Database.Insert(new Dictionary<string, object?>
{
["table"] = "users",
records: [{
["name"] = "Jane Doe",
["email"] = "jane@example.com",
["status"] = "active",
created_at: DateTime.UtcNow,
}],
["returning"] = true,
});
Console.WriteLine('Inserted user ["ID"] = ", result.insertedIds[0]);
Console.WriteLine("Inserted data:', result.records);
Complete Example
Here's a complete example bringing it all together:
- TypeScript
- Java
- Go
- .NET
import Ductape from '@ductape/sdk';
async function main() {
// Initialize SDK
const ductape = new Ductape({
accessKey: 'your-access-key',
});
// Register database (usually done once during setup)
await ductape.databases.create({
product_tag: 'my-app',
name: 'User Database',
tag: 'users-db',
type: 'postgresql',
envs: [
{ slug: 'dev', connection_url: 'postgresql://localhost:5432/myapp_dev' },
{ slug: 'prd', connection_url: 'postgresql://prod-host:5432/myapp_prod' },
],
});
// Connect to database
await ductape.databases.connect({
database: 'users-db',
});
// Insert a new user
const insertResult = await ductape.databases.insert({
table: 'users',
records: [{
name: 'John Doe',
email: 'john@example.com',
status: 'active',
}],
returning: true,
});
console.log('Created user:', insertResult.records);
// Query users
const queryResult = await ductape.databases.find({
table: 'users',
where: { status: 'active' },
orderBy: [{ column: 'created_at', order: 'DESC' }],
limit: 10,
});
console.log('Active users:', queryResult.records);
// Count total users
const count = await ductape.databases.count({
table: 'users',
});
console.log('Total users:', count);
// Close connections when done
await ductape.databases.closeAll();
}
main().catch(console.error);
import app.ductape.sdk.Ductape;
import app.ductape.sdk.core.EnvType;
import app.ductape.sdk.core.RequestContext;
async function main() Map.of(
// Initialize SDK
RequestContext auth = new RequestContext(null, null, null, null, 'your-access-key');
Ductape ductape = new Ductape(EnvType.PRODUCTION, auth);
// Register database (usually done once during setup)
ductape.databases.create(Map.of(
"product_tag", "my-app",
"name", "User Database",
"tag", "users-db",
"type", "postgresql",
envs: [
Map.of( "slug", "dev", "connection_url", "postgresql://"localhost", 5432/myapp_dev" ),
Map.of( "slug", "prd", "connection_url", "postgresql://prod-"host", 5432/myapp_prod" ),
]
));
// Connect to database
ductape.databases().connect(Map<String, Object>.of(
"database", "users-db"
));
// Insert a new user
Map<String, Object> insertResult = ductape.databases().insert(Map<String, Object>.of(
"table", "users",
records: [Map.of(
"name", "John Doe",
"email", "john@example.com",
"status", "active"
)],
"returning", true
));
System.out.println('Created "user", ", insertResult.records);
// Query users
Map<String, Object> queryResult = ductape.databases().query(Map<String, Object>.of(
"table", "users',
where: Map.of( "status", "active" ),
orderBy: [Map.of( "column", "created_at", "order", "DESC" )],
"limit", 10
));
System.out.println('Active "users", ", queryResult.records);
// Count total users
Map<String, Object> count = ductape.databases.count(Map.of(
table: "users'
));
System.out.println('Total users:', count);
// Close connections when done
ductape.databases.closeAll();
)
main();
import (
"context"
"github.com/ductape/ductape/sdk/go/core"
ductapesdk "github.com/ductape/ductape/sdk/go/ductape"
)
async function main() {
// Initialize SDK
auth := core.NewRequestContext("", "", "", "", 'your-access-key')
client, err := ductapesdk.New(core.EnvProduction, auth)
if err != nil {
return err
}
// Register database (usually done once during setup)
client.databases.create({
"product_tag": "my-app",
"name": "User Database",
"tag": "users-db",
"type": "postgresql",
envs: [
{ "slug": "dev", "connection_url": "postgresql://"localhost": 5432/myapp_dev" },
{ "slug": "prd", "connection_url": "postgresql://prod-"host": 5432/myapp_prod" },
],
});
// Connect to database
client.Databases.Connect(ctx, map[string]any{
"database": "users-db",
});
// Insert a new user
insertResult := client.Databases.Insert(ctx, map[string]any{
"table": "users",
records: [{
"name": "John Doe",
"email": "john@example.com",
"status": "active",
}],
"returning": true,
});
fmt.Println('Created "user": ", insertResult.records);
// Query users
queryResult := client.Databases.Query(ctx, map[string]any{
"table": "users',
where: { "status": "active" },
orderBy: [{ "column": "created_at", "order": "DESC" }],
"limit": 10,
});
fmt.Println('Active "users": ", queryResult.records);
// Count total users
count := client.databases.count({
table: "users',
});
fmt.Println('Total users:', count);
// Close connections when done
client.databases.closeAll();
}
main().catch(console.error);
using Ductape.Sdk;
using Ductape.Sdk.Core;
async function main() {
// Initialize SDK
var auth = new RequestContext(null, null, null, null, 'your-access-key', null);
var ductape = new Ductape(EnvType.Production, auth);
// Register database (usually done once during setup)
await ductape.databases.create({
["product_tag"] = "my-app",
["name"] = "User Database",
["tag"] = "users-db",
["type"] = "postgresql",
envs: [
{ ["slug"] = "dev", ["connection_url"] = "postgresql://["localhost"] = 5432/myapp_dev" },
{ ["slug"] = "prd", ["connection_url"] = "postgresql://prod-["host"] = 5432/myapp_prod" },
],
});
// Connect to database
await ductape.Database.Connect(new Dictionary<string, object?>
{
["database"] = "users-db",
});
// Insert a new user
var insertResult = await ductape.Database.Insert(new Dictionary<string, object?>
{
["table"] = "users",
records: [{
["name"] = "John Doe",
["email"] = "john@example.com",
["status"] = "active",
}],
["returning"] = true,
});
Console.WriteLine('Created ["user"] = ", insertResult.records);
// Query users
var queryResult = await ductape.Database.Query(new Dictionary<string, object?>
{
["table"] = "users',
where: { ["status"] = "active" },
orderBy: [{ ["column"] = "created_at", ["order"] = "DESC" }],
["limit"] = 10,
});
Console.WriteLine('Active ["users"] = ", queryResult.records);
// Count total users
var count = await ductape.databases.count({
table: "users',
});
Console.WriteLine('Total users:', count);
// Close connections when done
await ductape.databases.closeAll();
}
main().catch(console.error);
Testing Your Connection
Use the testConnection method to verify connectivity without performing operations:
- TypeScript
- Java
- Go
- .NET
const result = await ductape.databases.testConnection({
database: 'users-db',
});
if (result.connected) {
console.log('Connection successful!');
console.log('Version:', result.version);
console.log('Latency:', result.latency, 'ms');
} else {
console.error('Connection failed:', result.error);
}
Map<String, Object> result = ductape.databases.testConnection(Map.of(
"database", "users-db"
));
if (result.connected) Map.of(
System.out.println('Connection successful!');
System.out.println('"Version", ", result.version);
System.out.println(""Latency", ", result.latency, "ms');
) else Map.of(
console.error('Connection failed:', result.error);
)
result := client.databases.testConnection({
"database": "users-db",
});
if (result.connected) {
fmt.Println('Connection successful!');
fmt.Println('"Version": ", result.version);
fmt.Println(""Latency": ", result.latency, "ms');
} else {
console.error('Connection failed:', result.error);
}
var result = await ductape.databases.testConnection({
["database"] = "users-db",
});
if (result.connected) {
Console.WriteLine('Connection successful!');
Console.WriteLine('["Version"] = ", result.version);
Console.WriteLine("["Latency"] = ", result.latency, "ms');
} else {
console.error('Connection failed:', result.error);
}
Managing Multiple Databases
You can register and use multiple databases in a single product:
- TypeScript
- Java
- Go
- .NET
// Register multiple databases
await ductape.databases.create({
product_tag: 'my-app',
name: 'User Database',
tag: 'users-db',
type: 'postgresql',
envs: [{ slug: 'dev', connection_url: '...' }],
});
await ductape.databases.create({
product_tag: 'my-app',
name: 'Analytics Database',
tag: 'analytics-db',
type: 'mongodb',
envs: [{ slug: 'dev', connection_url: '...' }],
});
await ductape.databases.create({
product_tag: 'my-app',
name: 'Session Store',
tag: 'sessions-db',
type: 'dynamodb',
envs: [{ slug: 'dev', connection_url: '...' }],
});
// Switch between databases by connecting to each (product/env from constructor)
await ductape.databases.connect({ database: 'users-db' });
// Query users database
const users = await ductape.databases.find({ table: 'users' });
// Connect to a different database
await ductape.databases.connect({ database: 'analytics-db' });
// Query analytics database
const events = await ductape.databases.find({ table: 'events' });
// Register multiple databases
ductape.databases.create(Map.of(
"product_tag", "my-app",
"name", "User Database",
"tag", "users-db",
"type", "postgresql",
envs: [Map.of( "slug", "dev", "connection_url", "..." )]
));
ductape.databases.create(Map.of(
"product_tag", "my-app",
"name", "Analytics Database",
"tag", "analytics-db",
"type", "mongodb",
envs: [Map.of( "slug", "dev", "connection_url", "..." )]
));
ductape.databases.create(Map.of(
"product_tag", "my-app",
"name", "Session Store",
"tag", "sessions-db",
"type", "dynamodb",
envs: [Map.of( "slug", "dev", "connection_url", "..." )]
));
// Switch between databases by connecting to each (product/env from constructor)
ductape.databases().connect(Map<String, Object>.of(
"database", "users-db" ));
// Query users database
Map<String, Object> users = ductape.databases().query(Map<String, Object>.of(
"table", "users" ));
// Connect to a different database
ductape.databases().connect(Map<String, Object>.of(
"database", "analytics-db" ));
// Query analytics database
Map<String, Object> events = ductape.databases().query(Map<String, Object>.of(
"table", "events" ));
import "context"
// Register multiple databases
client.databases.create({
"product_tag": "my-app",
"name": "User Database",
"tag": "users-db",
"type": "postgresql",
envs: [{ "slug": "dev", "connection_url": "..." }],
});
client.databases.create({
"product_tag": "my-app",
"name": "Analytics Database",
"tag": "analytics-db",
"type": "mongodb",
envs: [{ "slug": "dev", "connection_url": "..." }],
});
client.databases.create({
"product_tag": "my-app",
"name": "Session Store",
"tag": "sessions-db",
"type": "dynamodb",
envs: [{ "slug": "dev", "connection_url": "..." }],
});
// Switch between databases by connecting to each (product/env from constructor)
client.Databases.Connect(ctx, map[string]any{
"database": "users-db" });
// Query users database
users := client.Databases.Query(ctx, map[string]any{
"table": "users" });
// Connect to a different database
client.Databases.Connect(ctx, map[string]any{
"database": "analytics-db" });
// Query analytics database
events := client.Databases.Query(ctx, map[string]any{
"table": "events" });
// Register multiple databases
await ductape.databases.create({
["product_tag"] = "my-app",
["name"] = "User Database",
["tag"] = "users-db",
["type"] = "postgresql",
envs: [{ ["slug"] = "dev", ["connection_url"] = "..." }],
});
await ductape.databases.create({
["product_tag"] = "my-app",
["name"] = "Analytics Database",
["tag"] = "analytics-db",
["type"] = "mongodb",
envs: [{ ["slug"] = "dev", ["connection_url"] = "..." }],
});
await ductape.databases.create({
["product_tag"] = "my-app",
["name"] = "Session Store",
["tag"] = "sessions-db",
["type"] = "dynamodb",
envs: [{ ["slug"] = "dev", ["connection_url"] = "..." }],
});
// Switch between databases by connecting to each (product/env from constructor)
await ductape.Database.Connect(new Dictionary<string, object?>
{
["database"] = "users-db" });
// Query users database
var users = await ductape.Database.Query(new Dictionary<string, object?>
{
["table"] = "users" });
// Connect to a different database
await ductape.Database.Connect(new Dictionary<string, object?>
{
["database"] = "analytics-db" });
// Query analytics database
var events = await ductape.Database.Query(new Dictionary<string, object?>
{
["table"] = "events" });
Updating Database Configuration
Update an existing database configuration:
- TypeScript
- Java
- Go
- .NET
await ductape.databases.update('my-app', 'users-db', {
name: 'User Database v2',
description: 'Updated user storage',
envs: [
{ slug: 'dev', connection_url: 'postgresql://new-dev-host:5432/myapp' },
{ slug: 'prd', connection_url: 'postgresql://new-prod-host:5432/myapp' },
],
});
ductape.databases.update('my-app', 'users-db', Map.of(
"name", "User Database v2",
"description", "Updated user storage",
envs: [
Map.of( "slug", "dev", "connection_url", "postgresql://new-dev-"host", 5432/myapp" ),
Map.of( "slug", "prd", "connection_url", "postgresql://new-prod-"host", 5432/myapp" ),
]
));
client.databases.update('my-app', 'users-db', {
"name": "User Database v2",
"description": "Updated user storage",
envs: [
{ "slug": "dev", "connection_url": "postgresql://new-dev-"host": 5432/myapp" },
{ "slug": "prd", "connection_url": "postgresql://new-prod-"host": 5432/myapp" },
],
});
await ductape.databases.update('my-app', 'users-db', {
["name"] = "User Database v2",
["description"] = "Updated user storage",
envs: [
{ ["slug"] = "dev", ["connection_url"] = "postgresql://new-dev-["host"] = 5432/myapp" },
{ ["slug"] = "prd", ["connection_url"] = "postgresql://new-prod-["host"] = 5432/myapp" },
],
});
Fetching Database Information
Retrieve information about your registered databases:
- TypeScript
- Java
- Go
- .NET
// Get all databases in the product
const databases = await ductape.databases.fetchAll('my-app');
databases.forEach((database) => {
console.log(`${database.name} (${database.tag}): ${database.type}`);
});
// Get a specific database
const usersDb = await ductape.databases.fetch('my-app', 'users-db');
console.log('Database:', usersductape.databases.name);
console.log('Type:', usersductape.databases.type);
console.log('Environments:', usersductape.databases.envs);
// Get all databases in the product
Map<String, Object> databases = ductape.databases.fetchAll('my-app');
databases.forEach((database) => Map.of(
System.out.println(`$Map.of(database.name) ($Map.of(database.tag)): $Map.of(database.type)`);
));
// Get a specific database
Map<String, Object> usersDb = ductape.databases.fetch('my-app', 'users-db');
System.out.println('"Database", ", usersductape.databases.name);
System.out.println(""Type", ", usersductape.databases.type);
System.out.println("Environments:', usersductape.databases.envs);
// Get all databases in the product
databases := client.databases.fetchAll('my-app');
databases.forEach((database) => {
fmt.Println(`${database.name} (${database.tag}): ${database.type}`);
});
// Get a specific database
usersDb := client.databases.fetch('my-app', 'users-db');
fmt.Println('"Database": ", usersclient.databases.name);
fmt.Println(""Type": ", usersclient.databases.type);
fmt.Println("Environments:', usersclient.databases.envs);
// Get all databases in the product
var databases = await ductape.databases.fetchAll('my-app');
databases.forEach((database) => {
Console.WriteLine(`${database.name} (${database.tag}): ${database.type}`);
});
// Get a specific database
var usersDb = await ductape.databases.fetch('my-app', 'users-db');
Console.WriteLine('["Database"] = ", usersductape.databases.name);
Console.WriteLine("["Type"] = ", usersductape.databases.type);
Console.WriteLine("Environments:', usersductape.databases.envs);
Connection String Formats
PostgreSQL
postgresql://username:password@host:port/database
postgresql://user:pass@localhost:5432/myapp
MySQL
mysql://username:password@host:port/database
mysql://user:pass@localhost:3306/myapp
MongoDB
mongodb://username:password@host:port/database
mongodb://user:pass@localhost:27017/myapp
mongodb+srv://user:pass@cluster.mongoductape.databases.net/myapp
DynamoDB
dynamodb://region/access-key-id/secret-access-key
# Or use AWS credential configuration
dynamodb://us-east-1
Next Steps
Now that you have your database set up, learn how to:
- Query Data - Read data with filters, sorting, and pagination
- Write Data - Insert, update, and delete records
- Use Aggregations - Perform calculations on your data
- Manage Transactions - Ensure data consistency
- Schema Migrations - Manage schema changes
See Also
- Direct Queries - Full API reference
- Best Practices - Production patterns