# `deleteQuery` Function
The `deleteQuery` function generates a DELETE SQL query based on the provided parameters. It supports filtering, joins, sorting, and limiting the number of rows to delete.
## Function Signature
```ts
export function deleteQuery<Tables extends string[]>(params: DeleteQueryParams<Tables>): string;
Parameters
table: The table to delete rows from.
Type: string
where: The condition to delete rows (WHERE clause).
Type: string
sort (optional): Sorting criteria for the DELETE query. Can be applied to the main table or related tables.
Type: SortType<Tables>
limit (optional): The maximum number of rows to delete.
Type: string | number
joins (optional): Joins to include in the query, supporting different JOIN types.
Type: JoinsType<Tables>
Example
const query = deleteQuery({
table: 'orders',
where: 'status = "pending"',
joins: [
{ type: 'INNER JOIN', table: 'customers', on: 'orders.customer_id = customers.id' }
],
sort: { orders: { order_date: -1 } },
limit: 10
});
console.log(query);
// Output:
// DELETE orders FROM orders
// INNER JOIN customers ON orders.customer_id = customers.id
// WHERE status = "pending"
// ORDER BY order_date DESC
// LIMIT 10;
2. insertQuery Function Documentation
# `insertQuery` Function
The `insertQuery` function generates an INSERT SQL query. It supports inserting one or more rows, handling timestamp fields, managing unique constraints, and handling duplicate key conflicts.
## Function Signature
```ts
export function insertQuery(params: insertQueryParams): string;
Parameters
table: The name of the table where data will be inserted.
Type: string
insertData: The data to insert into the table, either as a single object or an array of objects.
# `selectSQL` Function
The `selectSQL` function builds a flexible MySQL SELECT query. It supports joins, aggregates, grouping, sorting, and more, to allow complex queries with various configurations.
## Function Signature
```ts
export function selectSQL<Tables extends string[]>(config: SelectQueryParams<Tables>): string;
Parameters
distinct (optional): Whether to apply DISTINCT to the query results.
Type: boolean
table (optional): The table to select data from.
Type: string
sort (optional): Sorting order for the query. Use 1 for ascending and -1 for descending.
Type: Record<string, 1 | -1>
limitSkip (optional): Limit and offset for pagination.
Type: { limit?: number; skip?: number }
columns (optional): Specific columns to select or * for all.