Members
(inner, constant) DatabaseTypeToInternalProtocol
- Description:
Protocol to use when connecting to the internal (cluster-local) endpoint of a database, as opposed to its public ingress URL.
This only needs an entry for database types whose
DatabaseTypeToProtocolvalue is not valid for the raw container port. CouchDB's public URL is HTTPS (TLS terminated at the ingress on port 443), but its internal container port (5984) speaks plaintext HTTP - there is no in-cluster TLS termination on that port. Other database types use non-HTTP schemes (postgres://, mysql://, redis://, clickhouse://) for both paths and are unaffected.
Protocol to use when connecting to the internal (cluster-local) endpoint of a database, as opposed to its public ingress URL.
This only needs an entry for database types whose DatabaseTypeToProtocol
value is not valid for the raw container port. CouchDB's public URL is
HTTPS (TLS terminated at the ingress on port 443), but its internal
container port (5984) speaks plaintext HTTP - there is no in-cluster TLS
termination on that port. Other database types use non-HTTP schemes
(postgres://, mysql://, redis://, clickhouse://) for both paths and are
unaffected.
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