or run

npx @tessl/cli init
Log in

Version

Files

tile.json

task.mdevals/scenario-1/

Data Type Converter

A utility for storing and retrieving JavaScript data types in a PostgreSQL database, demonstrating proper handling of type conversions.

The implementation should connect to PostgreSQL using the standard connection parameters (host, port, database, user, password) and handle table creation automatically.

Capabilities

Store JavaScript values in PostgreSQL

Build a function that stores various JavaScript data types (strings, numbers, booleans, dates, arrays, and null values) into a PostgreSQL table and retrieves them back, preserving their types correctly.

  • Given a string value "hello", storing and retrieving it returns the same string "hello" @test
  • Given a number value 42, storing and retrieving it returns the number 42 @test
  • Given a boolean value true, storing and retrieving it returns true @test
  • Given a Date object for 2024-01-15T10:30:00Z, storing and retrieving it returns a Date object with the same timestamp @test
  • Given an array [1, 2, 3], storing and retrieving it returns an array [1, 2, 3] @test
  • Given a null value, storing and retrieving it returns null @test

Handle multiple data types in a single operation

Build a function that stores multiple different data types in a single database operation using parameterized queries.

  • Given multiple values of different types (string, number, boolean, date), all values are stored correctly in a single INSERT operation @test

Implementation

@generates

API

/**
 * Stores a value in the database with automatic type conversion.
 *
 * @param {any} value - The JavaScript value to store (string, number, boolean, Date, Array, null)
 * @returns {Promise<any>} The retrieved value from the database
 */
async function storeAndRetrieve(value) {
  // IMPLEMENTATION HERE
}

/**
 * Stores multiple values in the database in a single operation.
 *
 * @param {Array<any>} values - Array of JavaScript values to store
 * @returns {Promise<Array<any>>} Array of retrieved values from the database
 */
async function storeMultiple(values) {
  // IMPLEMENTATION HERE
}

module.exports = {
  storeAndRetrieve,
  storeMultiple
};

Dependencies { .dependencies }

pg { .dependency }

PostgreSQL client for Node.js with automatic type conversion support.