QueryBuilder class

A fluent SQL query builder for constructing and executing database queries.

Each terminal operation (get, first, insert, etc.) creates a snapshot of the current state before executing, so the builder can be safely reused.

Constructors

QueryBuilder(String _table, DatabaseExecutor _executor)
Creates a new QueryBuilder for the given table name.

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

count() Future<int>
Executes a COUNT query and returns the total number of matching rows.
delete() Future<QueryResult>
Executes a DELETE statement.
first() Future<Map<String, dynamic>?>
Executes a SELECT query and returns only the first matching row.
get() Future<List<Map<String, dynamic>>>
Executes a SELECT query and returns the matching rows.
groupBy(String column) QueryBuilder
Adds a GROUP BY clause.
having(String column, String operator, dynamic value) QueryBuilder
Adds a HAVING clause.
insert(Map<String, dynamic> data) Future<QueryResult>
Executes an INSERT statement with the provided data. Returns the query result (includes affected rows).
join(String table, String col1, String operator, String col2) QueryBuilder
Adds an INNER JOIN clause.
leftJoin(String table, String col1, String operator, String col2) QueryBuilder
Adds a LEFT JOIN clause.
limit(int value) QueryBuilder
Adds a LIMIT clause.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
offset(int value) QueryBuilder
Adds an OFFSET clause.
orderBy(String column, [String direction = 'ASC']) QueryBuilder
Adds an ORDER BY clause for column and direction.
orWhere(String column, String operator, dynamic value) QueryBuilder
Adds a WHERE clause with an OR conjunction.
rightJoin(String table, String col1, String operator, String col2) QueryBuilder
Adds a RIGHT JOIN clause.
select(List<String> columns) QueryBuilder
Specifies the columns to be selected. Defaults to ['*'].
toString() String
A string representation of this object.
inherited
update(Map<String, dynamic> data) Future<QueryResult>
Executes an UPDATE statement with the provided data.
where(String column, String operator, dynamic value) QueryBuilder
Adds a WHERE clause with an AND conjunction.
whereIn(String column, List values) QueryBuilder
Adds a WHERE column IN (...) clause.
whereNotNull(String column) QueryBuilder
Adds a WHERE column IS NOT NULL clause.
whereNull(String column) QueryBuilder
Adds a WHERE column IS NULL clause.

Operators

operator ==(Object other) bool
The equality operator.
inherited