database_query_builder 0.0.5 database_query_builder: ^0.0.5 copied to clipboard
The Database Query Builder for Dart provides an easy, efficient, and fluid interface for building or running database queries.
Database: Query Builder
Developed with 💙 by Jean Roldan
# Introduction #
The Database Query Builder for Dart provides an easy, efficient, and fluid interface for building or running database queries. It can be used to perform most basic (Temporary) database operations and works perfectly with postgresql we hope to add support for other managers later.
This project will momentarily depend on our source postgres library to connect to this manager and execute queries, although it is true, there are multiple ORM-based libraries, but we want to do something of our own, something CRAZY!
# Data Methods #
We have several methods to bring information from our queries:
get()
Returns a list of type map<String,dynamic> depending on our queries
getModel()
Returns a list of a strongly typed class to generate direct models
ToSql()
gets the query generated by the query builder does not require a database connection, you can use this function to generate the required SQL helping you avoid SQL injections
DB.table('products').get();
DB.table('products').getModel<Product>(Product.fromJson);
DB.table('products').first();
DB.table('products').firstModel();
DB.table('products').toSql();
Raw Expressions #
🦖
# INSERT INTO Statements #
Inserts Basic #
Provides an insert
method that can be used to insert records using a map(key,value)
final numRowAffected = await DB.table('persons').insert({
'firstName': 'testFirstName',
'lastName': 'testLastName',
'age': 30,
}).save()
Inserts Multiple #
You can insert multiple records at once using the insertAll
method by passing a list of map(key,value)
final sql03 = await DB.table('persons').insertAll([
{
'firstName': 'testFirstName1',
'lastName': 'testLastName1',
'age': 10,
},
{
'firstName': 'testFirstName2',
'lastName': 'testLastName2',
'age': 20,
},
{
'firstName': 'testFirstName3',
'lastName': 'testLastName3',
'age': 30,
}
]).save();
Inserts Get ID #
🦖
# SELECT Statements #
select #
DB.table('persons').select(['firstName','age']).get();
distinct #
🦖
# WHERE Statements #
Where Clauses #
🦖
Where Nested #
🦖
Where IN #
🦖
Where OR #
🦖
Where NULL #
🦖
Where EXIST #
🦖
Where NOT EXIST #
🦖
# UPDATE SET Statements #
update #
DB.table('persons')
.update({'firstName': 'new first name', 'lastName': 'new last name'})
.save();
update with conditional #
DB.table('persons')
.update({'firstName': 'new first name', 'lastName': 'new last name'})
.where('id', '1')
.save();