Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the PostgreSQL client from Deno's standard library.
Deno
import { Client } from "https://deno.land/x/postgres@v[1]/mod.ts";
Attempts:
3 left
💡 Hint
Common Mistakes
Using an incorrect or outdated version number.
Forgetting to include the version in the import URL.
✗ Incorrect
The correct version to import the PostgreSQL client is 0.17.1 for compatibility.
2fill in blank
mediumComplete the code to create a new PostgreSQL client instance with a connection string.
Deno
const client = new Client({ connectionString: "[1]" });Attempts:
3 left
💡 Hint
Common Mistakes
Using a MySQL or SQLite connection string format.
Using HTTP protocol instead of PostgreSQL.
✗ Incorrect
The connection string for PostgreSQL starts with 'postgres://'.
3fill in blank
hardFix the error in the async function to connect to the database.
Deno
async function connectDB() {
await client.[1]();
}Attempts:
3 left
💡 Hint
Common Mistakes
Using 'open' or 'start' which are not valid methods.
Forgetting to await the connection.
✗ Incorrect
The correct method to connect the client is 'connect()'.
4fill in blank
hardFill both blanks to query all rows from the 'users' table and log the results.
Deno
const result = await client.[1]("SELECT * FROM users"); console.[2](result.rows);
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'queryArray' which returns arrays but is less common here.
Using 'print' instead of 'log' for console output.
✗ Incorrect
Use 'query' to run the SQL and 'log' to print the results.
5fill in blank
hardFill all three blanks to insert a new user into the 'users' table safely using parameters.
Deno
await client.[1]("INSERT INTO users (name, email) VALUES ($1, $2)", [2]);
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'execute' which is not a method in this client.
Passing parameters as a string instead of an array.
✗ Incorrect
Use 'query' with parameter array to safely insert data.
