UNPKG

arlet-db

Version:

A simple database manager for Node.js

43 lines (34 loc) 1.74 kB
[🏠 Inicio](../README.md) ## Method: select ### Description: The select method retrieves specific columns from a table based on given criteria and options. It supports filtering, sorting, and limiting the results, including complex queries with logical and comparison operators. ### Usage: ````javascript async select(tableName, columns, criteria = {}, options = {}) ```` #### Parameters: * tableName (String): The name of the table from which to select data. * columns (Array): An array of column names to be retrieved. If empty, all columns are selected. * criteria (Object, optional): An object containing key-value pairs to filter the data. Each value can be an object specifying an operator and value for more complex conditions. * 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, each representing a row with the specified columns. Example: ````javascript const db = new ArletDb('path/to/database', 'myDatabase'); const result = await db.select('users', ['name', 'email'], { age: {operator: '=', value: 30} }, { sort: ['name', 'asc'], limit: 10 }); console.log(result); //example of select with operator like let value = 'Jhon Doe'; db.select('logs', [], { nombres: { $like: `%${value}%` } }) .then((logs) => { console.log(logs); }) .catch((error) => { console.log({ error: error }); }); ```` #### Errors: * Throws an error if the table does not exist.