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
tablename.
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
COUNTquery and returns the total number of matching rows. -
delete(
) → Future< QueryResult> -
Executes a
DELETEstatement. -
first(
) → Future< Map< String, dynamic> ?> -
Executes a
SELECTquery and returns only the first matching row. -
get(
) → Future< List< Map< >String, dynamic> > -
Executes a
SELECTquery and returns the matching rows. -
groupBy(
String column) → QueryBuilder -
Adds a
GROUP BYclause. -
having(
String column, String operator, dynamic value) → QueryBuilder -
Adds a
HAVINGclause. -
insert(
Map< String, dynamic> data) → Future<QueryResult> -
Executes an
INSERTstatement with the provideddata. 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
LIMITclause. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
offset(
int value) → QueryBuilder -
Adds an
OFFSETclause. -
orderBy(
String column, [String direction = 'ASC']) → QueryBuilder -
Adds an
ORDER BYclause forcolumnanddirection. -
orWhere(
String column, String operator, dynamic value) → QueryBuilder -
Adds a
WHEREclause with anORconjunction. -
rightJoin(
String table, String col1, String operator, String col2) → QueryBuilder - Adds a RIGHT JOIN clause.
-
select(
List< String> columns) → QueryBuilder -
Specifies the
columnsto be selected. Defaults to['*']. -
toString(
) → String -
A string representation of this object.
inherited
-
update(
Map< String, dynamic> data) → Future<QueryResult> -
Executes an
UPDATEstatement with the provideddata. -
where(
String column, String operator, dynamic value) → QueryBuilder -
Adds a
WHEREclause with anANDconjunction. -
whereIn(
String column, List values) → QueryBuilder -
Adds a
WHERE column IN (...)clause. -
whereNotNull(
String column) → QueryBuilder -
Adds a
WHERE column IS NOT NULLclause. -
whereNull(
String column) → QueryBuilder -
Adds a
WHERE column IS NULLclause.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited