sql_helper 0.1.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 78

SQLHelper #

Based on SqfLite

Usage #

    List<String> tables = new List();
    tables.add("CREATE TABLE Test (id INTEGER PRIMARY KEY, name TEXT, value INTEGER, num REAL)");

    DatabaseHelper databaseHelper =
            SqlHelperBuilder(dbName: "test.db", dbVersion: 1).build();

    await databaseHelper.init(tables);

    /// See more in example.

[0.1.2] - Fix SQLEntity method

[0.1.1] - Add SQLEntity (Utility class)

[0.1.0] - SQLHelper Base


import 'package:flutter/foundation.dart';
import 'package:sql_helper/sql_helper.dart';

void main() {
  List<String> tables = new List();

  DatabaseHelper databaseHelper =
      SqlHelperBuilder(dbName: "test.db", dbVersion: 1).build();

  /// Init Database
  databaseHelper.init(tables).then((result) async {
    print("Database Initializated");

    UserEntity userEntity = new UserEntity();
    userEntity.firstName = "Brian";
    userEntity.lastName = "Dev";
    userEntity.email = "bdev@example.com";
    userEntity.token = "eap1359h21h4pac";

    ///Insert record
    int idRecord = await databaseHelper.insertRecord(
        UserEntity.tableName, userEntity.toMap());

    /// Get Records
    List<Map> records = await databaseHelper.getRecords(UserEntity.tableName);
    debugPrint("Results : $records");

    /// Update Records
    userEntity.firstName = "Steve";

    await databaseHelper.updateRecord(
        table: UserEntity.tableName,
        whereColumns: [UserEntity.columnId],
        valuesCondition: [idRecord],
        updateData: userEntity.toMap());

    /// Get Records updated
    List<Map> records2 = await databaseHelper.getRecords(UserEntity.tableName);
    debugPrint("Results : $records2");

    /// Delete Records
    await databaseHelper.deleteRecord(
        table: UserEntity.tableName,
        whereColumns: [UserEntity.columnId],
        valuesCondition: [idRecord]);

    /// Get Records updated
    List<Map> emptyRecords =
        await databaseHelper.getRecords(UserEntity.tableName);
    debugPrint("Results : $emptyRecords");
  }, onError: (e) {
    print("DatabaseError: $e");

/// Model
class UserEntity implements SQLEntity {
  int id;
  String username;
  String email;
  String firstName;
  String lastName;
  String token;

  static final String tableName = "User";
  static final String columnId = "id"; //INTEGER PRIMARY KEY
  static final String columnUsername = "username"; //TEXT
  static final String columnEmail = "email"; //TEXT
  static final String columnFirstName = "firstName"; //TEXT
  static final String columnLastName = "lastname"; // TEXT
  static final String columnToken = "token";

  /// [createTable] is oldMethod for create new Table
  static String createTable() {
    return '''CREATE TABLE $tableName (
      $columnId INTEGER PRIMARY KEY autoincrement,
      $columnUsername TEXT,
      $columnEmail TEXT,
      $columnFirstName TEXT,
      $columnLastName TEXT,
      $columnToken TEXT

  /// [createTableNewMethod] is new Method for create new Table
  static String createTableNewMethod() {
    return SQLEntity.generateTable(tableName)
        .integer(columnId, primaryKey: true, autoincrement: true)


  UserEntity.fromMap(Map<String, dynamic> map) {
    id = map[columnId];
    username = map[columnUsername];
    email = map[columnEmail];
    firstName = map[columnFirstName];
    lastName = map[columnLastName];
    token = map[columnToken];

  /// Implement  Map<String, dynamic> map = {}
  Map<String, dynamic> toMap() {
    Map<String, dynamic> map = {
      columnUsername: username,
      columnEmail: email,
      columnFirstName: firstName,
      columnLastName: lastName,
      columnToken: token
    if (id != null) map[columnId] = id;
    return map;

Use this package as a library

1. Depend on it

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

  sql_helper: ^0.1.2

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

Alternatively, your editor might support 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:sql_helper/sql_helper.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

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

  • Dart: 2.7.0
  • pana: 0.13.4
  • Flutter: 1.12.13+hotfix.5


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
path ^1.6.4 1.6.4
sqflite ^1.1.5 1.2.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
synchronized 2.1.1
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies