sql_helper 0.1.0

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.0] - SQLHelper Base

example/main.dart

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

void main() {
  List<String> tables = new List();
  tables.add(UserEntity.createTable());

  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 {
  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";

  static String createTable() {
    return '''CREATE TABLE $tableName (
      $columnId INTEGER PRIMARY KEY autoincrement,
      $columnUsername TEXT,
      $columnEmail TEXT,
      $columnFirstName TEXT,
      $columnLastName TEXT,
      $columnToken TEXT
      )''';
  }

  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;
  }

  UserEntity();

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

Use this package as a library

1. Depend on it

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


dependencies:
  sql_helper: ^0.1.0

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';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
7
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]
53
Learn more about scoring.

We analyzed this package on Sep 20, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.0
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.2

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Dependencies

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