or run

npx @tessl/cli init
Log in

Version

Files

tile.json

task.mdevals/scenario-6/

Database Connection Configuration Parser

A utility that parses various database connection configuration formats and extracts connection details into a standardized object structure.

Capabilities

Parse standard connection URLs

  • Given a connection string postgresql://user:pass@localhost:5432/mydb, it extracts user as "user", password as "pass", host as "localhost", port as 5432, and database as "mydb" @test
  • Given a connection string postgres://admin@127.0.0.1/testdb, it extracts user as "admin", host as "127.0.0.1", and database as "testdb" with default port @test

Parse connection URLs with query parameters

  • Given a connection string postgres://user@host/db?sslmode=require&application_name=myapp, it extracts the SSL mode as "require" and application name as "myapp" in the configuration object @test
  • Given a connection string with multiple SSL parameters like postgres://user@host/db?sslcert=/path/cert.pem&sslkey=/path/key.pem, it extracts SSL certificate and key paths in the configuration @test

Parse Unix domain socket connections

  • Given a connection string /var/run/postgresql mydb, it identifies the Unix socket path as "/var/run/postgresql" and database as "mydb" @test
  • Given a socket protocol string socket:/tmp/pg.sock?db=testdb, it extracts the socket path and database name @test

Handle encoded characters in URLs

  • Given a connection string with URL-encoded password like postgres://user:p%40ssw0rd@host/db, it correctly decodes the password as "p@ssw0rd" @test

Implementation

@generates

API

/**
 * Parses a database connection string and returns a configuration object.
 *
 * @param {string} connectionString - The connection string to parse (supports PostgreSQL URL format, Unix sockets)
 * @returns {Object} Configuration object with connection details (user, password, host, port, database, ssl options, etc.)
 * @throws {Error} Throws an error if the connection string format is invalid
 */
function parseConnectionString(connectionString) {
  // IMPLEMENTATION HERE
}

module.exports = {
  parseConnectionString
};

Dependencies { .dependencies }

pg { .dependency }

Provides PostgreSQL client functionality and connection string parsing support.

@satisfied-by