Show Tables

Example
Prompt
Code

Create a table with filters

  • Query Execution: It runs an SQL query to select all records from the users table where the creationDate is within a specified date range (dateStart to dateEnd). The query parameters are taken from req.form.
  • Result Processing: It awaits the result of the query.
  • Result Handling: It passes the query result to the table method of the res parameter and returns the processed res
Example
Prompt
Code

Show custom HTML

This function is likely used in a web application to fetch and display a list of users in a formatted table, including visual indicators for user status and avatars. The function leverages asynchronous operations to handle database queries and processes the data into a structure suitable for frontend display.

Example
Prompt
Code

Tutorial

Step 1 - Get the start and end dates from the form

Get the start and end dates from the form: The fn function expects to receive the start and end dates from the form provided in req.form.

ts
const fn = async function (req: Request, res: Response) { const { startDate, endDate } = req.form; };

Step 2 - Build the SQL query

Build the SQL query: Use the provided dates to construct the SQL query that will select the data from the database according to the date range.

ts
const fn = async function (req: Request, res: Response) { const { startDate, endDate } = req.form; const sql = ` SELECT * FROM table WHERE date BETWEEN :startDate AND :endDate `; const replacements = { startDate, endDate }; };

Step 3 - Execute the query and get the results

Execute the query and get the results: Use the query method provided in req to execute the SQL query and get the data from the database.

ts
const fn = async function (req: Request, res: Response) { const { startDate, endDate } = req.form; const sql = ` SELECT * FROM table WHERE date BETWEEN :startDate AND :endDate `; const replacements = { startDate, endDate }; const rows = await req.query(sql, replacements); };

Step 4 - Display the results

Display the results: Use the table method provided in req to send the query results as a table response.

ts
const fn = async function (req: Request, res: Response) { const { startDate, endDate } = req.form; const sql = ` SELECT * FROM table WHERE date BETWEEN :startDate AND :endDate `; const replacements = { startDate, endDate }; const rows = await req.query(sql, replacements); return res.table(rows); };

With these steps, you can complete the fn function to show the results in a table filtered by start and end dates. Make sure to adjust the code according to your application's specifications and structure.

On this page

Show Tables

Create a table with filters

Show custom HTML

Tutorial

Step 1 - Get the start and end dates from the form

Step 2 - Build the SQL query

Step 3 - Execute the query and get the results

Step 4 - Display the results

View this page on
GitHub

Do you have specific enterprise needs? Contact our sales team.

get enterprise

Make your business efficient in seconds.

Create dashboards and backoffices in seconds
Start now