sql_build_database 1.0.5

sql_build_database #

A new Flutter package to create a database structure simply and quickly.

Example use #

Add depencencies

  dependencies:
    sql_build_database:^1.0.5

SBDColumnDataType #

  • INTEGER
  • TEXT
  • REAL
  • BLOB
enum SBDColumnDataType {INTEGER,TEXT,REAL,BLOB}

SBDColum #

  • name
  • type
  • isUnique
  • isNoNull
  • defaultValue
  • isPrimaryKey
  • isAutoIncrement
  • foreignKey
SBDColumn(   
  name: 'COLUMN_NAME',
  type: SBDColumnDataType.INTEGER,
  isUnique:true,
  isNotNull:true,
  defaultValue:1,
  isPrimaryKey:true,
  isAutoIncrement:true,
  foreignKey:['table1','COLUM_NAME']
);

SBDTable #

  • name
  • primaryKeyName
  • columns
 SBDTable(
    name: 'users',
    primaryKeyName: 'USER_CODE',
    columns: [
       SBDColumn(
         name: 'USER_NAME',
         type: SBDColumnDataType.TEXT,
         isNotNull: true,
       ),
       SBDColumn(
         name: 'USER_EMAIL',
         type: SBDColumnDataType.TEXT,
         isNotNull: true,
         isUnique: true,
       ),
       SBDColumn(
         name: 'USER_ACTIVE',
         type: SBDColumnDataType.INTEGER,
         isNotNull: true,
         defaultValue: 1,
       ),
    ],
    initialInserts: [
        {'USER_CODE':1,'USER_NAME':'Danilo Dos Satos Carreiro','USER_EMAIL':'danilocarsan@gmail.com','USER_ACTIVE':1},
    ],
    execInitialInserts: true
 )

print(tb.build()); #

CREATE TABLE users (USER_CODE INTEGER PRIMARY KEY AUTOINCREMENT,USER_NAME TEXT NOT NULL,USER_EMAIL TEXT NOT NULL UNIQUE,USER_ACTIVE INTEGER NOT NULL DEFAULT 1);

INSERT INTO users(USER_CODE,USER_NAME,USER_EMAIL,USER_ACTIVE)VALUES('1','Danilo Dos Satos Carreiro','danilocarsan@gmail.com','1');

print(tb.initialInserts()) #

[
  INSERT INTO users(USER_CODE,USER_NAME,USER_EMAIL,USER_ACTIVE)VALUES('1','Danilo Dos Satos Carreiro','danilocarsan@gmail.com','1');
]

#SBD

   SBD([
     SBDTable(
       name: 'users',
       primaryKeyName: 'USER_CODE',
       columns: [
           SBDColumn(
             name: 'USER_NAME',
             type: SBDColumnDataType.TEXT,
             isNotNull: true,
           ),
           SBDColumn(
             name: 'USER_EMAIL',
             type: SBDColumnDataType.TEXT,
             isNotNull: true,
             isUnique: true,
           ),
           SBDColumn(
             name: 'USER_ACTIVE',
             type: SBDColumnDataType.INTEGER,
             isNotNull: true,
             defaultValue: 1,
           ),
       ]
     ),
     SBDTable(
      name: 'logs',
      primaryKeyName: 'LOG_CODE',
      columns: [
        SBDColumn(
          name: 'MESSAGE',
          type: SBDColumnDataType.TEXT,
          isNotNull: true,
        ),
        SBDColumn(
           name: 'LOG_USER_CODE',
           isNotNull: true,
           foreignKey: ['users', 'USER_CODE']
        )
      ]
     )
   ]);

print(db.build()); #

CREATE TABLE users (
   USER_CODE INTEGER PRIMARY KEY AUTOINCREMENT,
   USER_NAME TEXT NOT NULL,
   USER_EMAIL TEXT NOT NULL UNIQUE,
   USER_ACTIVE INTEGER NOT NULL DEFAULT 1
 );
 
 CREATE TABLE logs (
   LOG_CODE INTEGER PRIMARY KEY AUTOINCREMENT,
   MESSAGE TEXT NOT NULL,
   LOG_USER_CODE TEXT NOT NULL REFERENCES users(USER_CODE),
   FOREIGN KEY (LOG_USER_CODE) REFERENCES users (USER_CODE)
 );

Getting Started #

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

[1.0.5] -

  • add initial inserts

[1.0.3] -

  • updated README and CHANGELOG and LICENCE

[1.0.2] -

  • updated README

[1.0.0] -

  • initial release

example/main.dart

// import 'package:sql_build_database/sql_build_database.dart';

import '../lib/sql_build_database.dart';

main() {
  var db = SBD([
    SBDTable(name: 'users', primaryKeyName: 'USER_CODE', columns: [
      SBDColumn(
        name: 'USER_NAME',
        type: SBDColumnDataType.TEXT,
        isNotNull: true,
      ),
      SBDColumn(
        name: 'USER_EMAIL',
        type: SBDColumnDataType.TEXT,
        isNotNull: true,
        isUnique: true,
      ),
      SBDColumn(
        name: 'USER_ACTIVE',
        type: SBDColumnDataType.INTEGER,
        isNotNull: true,
        defaultValue: 1,
      ),
    ],
    initialInserts: [
        {'USER_CODE':1,'USER_NAME':'Danilo Dos Satos Carreiro','USER_EMAIL':'danilocarsan@gmail.com','USER_ACTIVE':1},
    ],
    execInitialInserts: true
    ),
    SBDTable(name: 'logs', primaryKeyName: 'LOG_CODE', columns: [
      SBDColumn(
        name: 'MESSAGE',
        type: SBDColumnDataType.TEXT,
        isNotNull: true,
      ),
      SBDColumn(
          name: 'LOG_USER_CODE',
          isNotNull: true,
          foreignKey: ['users', 'USER_CODE'])
    ])
  ]);

  print(db.build());
}

Use this package as a library

1. Depend on it

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


dependencies:
  sql_build_database: ^1.0.5

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_build_database/sql_build_database.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
37
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
68
Learn more about scoring.

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

  • Dart: 2.7.1
  • pana: 0.13.5
  • Flutter: 1.12.13+hotfix.7

Health issues and suggestions

Document public APIs. (-1 points)

39 out of 39 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test