fluent_query_builder 1.0.10

  • Readme
  • Changelog
  • Example
  • Installing
  • new50

A dart library that allows you to execute SQL queries in the PostgreSQL database in a fluent way, is very easy to execute. This library implements POOL of connections. This lib implements the vast majority of SQL statements and clauses

Soon it will also support mysql and ORM without reflection and without code generation in a simple and consistent way.

Usage #

A simple query builder usage example:

import 'package:fluent_query_builder/fluent_query_builder.dart';

void main() {
  final com = DBConnectionInfo(
    host: 'localhost',
    database: 'test',
    port: 5432,
    username: 'root',
    password: '123456',
    charset: 'utf8',
    schemes: ['public'],
  );
  
  DBLayer.connect(com).then((db) {
    final query = db
        .select()
        //.fields(['login', 'idSistema', 's.sigla'])
        //.fieldRaw('DISTINCT jubarte.sistemas.sigla as')
        .from('user', alias: 't')
        .leftJoin('systems', 's.id', '=', 't."idSystem"', alias: 's')
        .whereRaw("login='jon.doe'")
        // .whereRaw("s.id='8'")
        // .where("login=?", 'jon.doe')
        /*.group('login')
      .group('t.idSistema')
      .group('sistemas.sigla');*/
        //.groupRaw('"login", "t"."idSystem", "s"."sigla"')
        .limit(1);
    // .groups(['login', 't.idSystem', 's.sigla']);

    query.firstAsMap().then((onValue) {
      print(onValue);
    });

  });
}

A simple ORM usage example:

import 'package:fluent_query_builder/fluent_query_builder.dart';

class Usuario implements OrmModelBase {
  Usuario({this.username});

  Usuario.fromMap(Map<String, dynamic> map) {
    id = map['id'] as int;
    username = map['username'] as String;
    password = map['password'] as String;
    ativo = map['ativo'] as bool;
    idPerfil = map['idPerfil'] as int;
  }

  int id;
  String username;
  String password;
  bool ativo;
  int idPerfil;

  @override
  Map<String, dynamic> toMap() {
    final Map<String, dynamic> data = Map<String, dynamic>();
    if (id != null) {
      data['id'] = id;
    }
    data['username'] = username;
    data['password'] = password;
    data['ativo'] = ativo;
    data['idPerfil'] = idPerfil;
    return data;
  }

  @override
  String get tableName => 'usuarios';
}

void main() {
  //configura a conexão
  final com = DBConnectionInfo(
    host: '192.168.133.13',
    database: 'sistemas',
    port: 5432,
    username: 'sisadmin',
    password: 's1sadm1n',
    charset: 'utf8',
    schemes: ['riodasostrasapp'],
  );
  
  DbLayer(factory: {Usuario: (x) => Usuario.fromMap(x)}).connect(com).then((db) {
    final query = db.select().from(Usuario().tableName);
    //get list of Usuario
    query.fetchAll<Usuario>().then((onValue) {
      print(onValue);
      //result [Instance of 'Usuario', Instance of 'Usuario', Instance of 'Usuario',...]
    });
  });
}

1.0.0 #

  • Initial version

1.0.1 #

  • fix

1.0.1 #

  • fix dartfmt

1.0.5 #

  • remove static DBLayer db conection

example/main.dart

import 'package:fluent_query_builder/fluent_query_builder.dart';

void main() {
  //configura a conexão
  final com = DBConnectionInfo(
    host: '192.168.133.13',
    database: 'sistemas',
    port: 5432,
    username: 'sisadmin',
    password: 's1sadm1n',
    charset: 'utf8',
    schemes: ['riodasostrasapp'],
  );

  /*DbLayer().connect(com).then((db) {
    final query = db
        .select()
        //.fields(['login', 'idSistema', 's.sigla'])
        //.fieldRaw('DISTINCT jubarte.sistemas.sigla as')
        //.from('usuarios', alias: 't')
        //  .leftJoin('sistemas', 's.id', '=', 't."idSistema"', alias: 's')
        // .whereRaw("login='isaque.neves'")
        // .whereRaw("s.id='8'")
        // .where("login=?", 'isaque.neves')
        /*.group('login')
      .group('t.idSistema')
      .group('sistemas.sigla');*/
        //.groupRaw('"login", "t"."idSistema", "s"."sigla"')
        .limit(1);
    // .groups(['login', 't.idSistema', 's.sigla']);

    query.firstAsMap().then((onValue) {
      print(onValue);
    });
  });*/

  DbLayer(factory: {Usuario: (x) => Usuario.fromMap(x)}).connect(com).then((db) {
    final query = db.select().from(Usuario().tableName);

    query.fetchAll<Usuario>().then((onValue) {
      print(onValue);
    });
  });
}

class Usuario implements OrmModelBase {
  Usuario({this.username});

  Usuario.fromMap(Map<String, dynamic> map) {
    id = map['id'] as int;
    username = map['username'] as String;
    password = map['password'] as String;
    ativo = map['ativo'] as bool;
    idPerfil = map['idPerfil'] as int;
  }

  int id;
  String username;
  String password;
  bool ativo;
  int idPerfil;

  @override
  Map<String, dynamic> toMap() {
    final Map<String, dynamic> data = Map<String, dynamic>();
    if (id != null) {
      data['id'] = id;
    }
    data['username'] = username;
    data['password'] = password;
    data['ativo'] = ativo;
    data['idPerfil'] = idPerfil;
    return data;
  }

  @override
  String get tableName => 'usuarios';
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  fluent_query_builder: ^1.0.10

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:fluent_query_builder/fluent_query_builder.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
50
Learn more about scoring.

We analyzed this package on Mar 27, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6

Health suggestions

Format lib/fluent_query_builder.dart.

Run dartfmt to format lib/fluent_query_builder.dart.

Format lib/src/db_layer.dart.

Run dartfmt to format lib/src/db_layer.dart.

Format lib/src/filter.dart.

Run dartfmt to format lib/src/filter.dart.

Fix additional 5 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/src/models/insert.dart (Run dartfmt to format lib/src/models/insert.dart.)
  • lib/src/models/query_builder.dart (Run dartfmt to format lib/src/models/query_builder.dart.)
  • lib/src/models/select.dart (Run dartfmt to format lib/src/models/select.dart.)
  • lib/src/query_executors/postgre_sql_executor.dart (Run dartfmt to format lib/src/query_executors/postgre_sql_executor.dart.)
  • lib/src/query_executors/query_executor.dart (Run dartfmt to format lib/src/query_executors/query_executor.dart.)

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
logging >=0.11.3 <2.0.0 0.11.4
pool >=1.2.3 <2.0.0 1.4.0
postgres >=1.0.2 <2.3.0 2.1.0
Transitive dependencies
async 2.4.1
buffer 1.0.6
charcode 1.1.3
collection 1.14.12
convert 2.1.1
crypto 2.1.4
path 1.6.4
stack_trace 1.9.3
typed_data 1.1.6
Dev dependencies
pedantic ^1.8.0
test ^1.6.0