UNPKG

arlet-db

Version:

A simple database manager for Node.js

38 lines (32 loc) 2 kB
[🏠 Inicio](../README.md) ## Method: selectJoin ### Description: The `selectJoin` method retrieves specific columns from multiple tables based on given criteria and options. It allows for filtering data from each table and combines the results. If no columns are specified, all columns will be included in the result. ### Usage: ````javascript async selectJoin(tables, columns = [], criteria = {}, options = {}) ```` ### Parameters: * **tables** (Array): An array of table names from which to select data. * **columns** (Array): An array of column names to be retrieved from each table. If empty, all columns are selected. * **criteria** (Object, optional): An object containing key-value pairs to filter the data. Default is an empty object. * **options** (Object, optional): An object containing additional options for sorting and limiting the results. Default is an empty object. * **sort** (Array): An array with two elements: the column to sort by and the order ('asc' or 'desc'). * **limit** (Number): The maximum number of results to return. ### Returns: * (Array): An array of objects representing the joined rows with the specified columns from each table. ### Example: ````javascript const db = new ArletDb('path/to/database', 'myDatabase'); // Joining data from 'users' and 'orders' tables const tables = ['users', 'orders']; const columns = ['name', 'amount']; // Columns to select const criteria = { userId: 1 }; // Filter criteria const options = { sort: ['amount', 'desc'], limit: 5 }; // Sorting and limiting options const result = await db.selectJoin(tables, columns, criteria, options); console.log(result); // Output: [{ name: 'Alice', amount: 100 }, ...] ```` ### Errors: * Throws an error if any of the tables do not exist. This version of the documentation provides a clearer description of the method's functionality, usage, and parameters. It also includes an example that demonstrates how to use the method with real data.