Need To Know
Need to Know
Before you start using the Database Query Builder, here are some essential things you should know to make the most of the library and its capabilities.
Key Features
Type Safety: The library is built with TypeScript, ensuring that your queries are type-safe. This means you'll receive compile-time validation for your SQL queries, preventing common mistakes like incorrect column names or table references.
Flexible Query Construction: Whether you're performing Insert, Update, Delete, or Select queries, the library offers flexible and intuitive methods for query construction. You'll be able to structure complex SQL queries easily, with minimal code.
Join Operations: The library supports various join operations like INNER JOIN, LEFT JOIN, RIGHT JOIN, and OUTER JOIN. This allows you to efficiently work with multiple tables in a single query.
Sorting Operations: Easily sort your query results using the SortType feature. Whether you want ascending or descending order, it’s simple to specify the sorting fields for your queries.
Insert and Update with Type-Safe Data: Insert or update records in your database while keeping the data type checks intact. You’ll get full TypeScript support when passing values to these queries.
Prerequisites
Before using the Database Query Builder, ensure you meet the following prerequisites:
Node.js: You should have Node.js (version 14 or higher) installed in your project. This library relies on modern JavaScript features that are best supported in newer Node.js versions.
TypeScript: Since this is a TypeScript library, it works best when integrated into a TypeScript project. However, it can also be used in plain JavaScript projects with proper type definitions.
Database: You need a relational database management system (RDBMS) such as MySQL, PostgreSQL, or SQLite. The library is designed to work with these databases, so ensure your setup matches the supported systems.
Setup and Configuration
Installation: The library is easy to install via npm or yarn. You can add it to your project using the following commands:
npm install database-query-builder
or
yarn add database-query-builder
Configuration: After installation, you’ll need to configure the database connection. This usually involves specifying your database credentials (e.g., host, user, password, database name) in a configuration file or directly within your code.
Supported Operations
The Database Query Builder library supports the following SQL operations:
- Insert Queries: Insert new rows into the database.
- Update Queries: Update existing records with new values.
- Delete Queries: Remove records from the database.
- Select Queries: Retrieve data, with support for joins and sorting.
Each operation allows for customization through various query types like where conditions, order by, group by, and more.
Example Use Cases
Here are some examples of what you can achieve with this query builder:
- Insert Query: Insert new records with type-safe data validation.
- Update Query: Update existing records, ensuring the correct fields are modified.
- Delete Query: Remove records using filters that specify which rows to delete.
- Select Query: Retrieve data from multiple tables, with support for complex join operations and sorting.
The following sections will go over each of these operations in more detail, providing you with a clear understanding of how to use the library effectively.
With this foundational understanding, you are ready to dive into the more specific details in the Getting Started section and explore how to integrate the query builder into your projects!