Introduction
The Lyger Query Builder provides a fluent interface for building and executing database queries. It’s inspired by Laravel’s Query Builder and offers a clean, readable syntax for working with databases.Basic Usage
Creating a Query Builder Instance
You can create a QueryBuilder instance in two ways:Select Queries
Retrieving All Records
Selecting Specific Columns
Getting a Single Record
The
first() method returns null if no record is found, while value() returns null if the column doesn’t exist.Where Clauses
Basic Where Clauses
Or Where Clauses
Where In Clauses
Null Checks
Ordering
Order By
Latest and Oldest
Convenient methods for ordering by timestamps:Limiting and Offset
Limit
Offset
Pagination
Thepaginate() method provides automatic pagination:
int
default:"15"
Number of records per page
int
default:"1"
Current page number
Joins
Inner Join
Left Join
Aggregates
Count
Exists
Insert Queries
Inserting Records
The
insert() method returns a boolean indicating success. The last insert ID is managed automatically by the underlying PDO connection.Update Queries
Updating Records
Update with Limit
Delete Queries
Deleting Records
Delete with Limit
Method Chaining
All Query Builder methods support fluent chaining:Parameter Binding
The Query Builder automatically handles parameter binding to prevent SQL injection:All user-provided values are automatically escaped and bound as parameters. You never need to manually escape values.
Complete Example
Here’s a comprehensive example combining multiple Query Builder features:Next Steps
Eloquent Models
Learn about the Eloquent ORM layer built on top of Query Builder
Migrations
Manage your database schema with migrations