@osaas/client-db

Methods

(async, inner) setupDatabase(ctx, type, name, opts)

Description:
  • Create a database instance if it does not exists and return the connection URL.

Example
import { Context } from '@osaas/client-core';
import { setupDatabase } from '@osaas/client-db';
import Redis from 'ioredis';

const ctx = new Context();
const dbUrl = await setupDatabase(ctx, 'valkey', 'myvalkey', { password: 'secret' });
const client = new Redis(dbUrl);
try {
  await client.subscribe('messages');
  console.log('Waiting for messages...');
  client.on('message', (channel, message) => {
    console.log(`Received message: ${message} from ${channel}`);
  });
} catch (err) {
  console.error('Error:', err);
}
Parameters:
Name Type Description
ctx Context

The Open Source Cloud configuration context.

type DatabaseType

The type of the database.

name string

The name of the database instance.

opts DatabaseOpts

The options for the database.

Returns:

The connection URL for the database.

Type Definitions

DatabaseOpts

Properties:
Name Type Attributes Description
username string <optional>

The username for the database

password string <optional>

The password for the database

rootPassword string <optional>

The root password for the database

database string <optional>

The database name

Type:
  • object