lessql 0.0.1-alpha

LesSQL #

LesSQL is a flutter plugin for sqlite.

Getting started #

1.Import LesSQL #

import 'package:lessql/lessql.dart';

2.Init databse #

Define DB

class FooDB extends LesDB{

  @override
  String getName() {
    return 'foo_db';
  }

  @override
  int getVersion() {
    return 1;
  }

}

Define table

class FooTable1 extends LesTable{

  @override
  List<String> getColumnNames() {
    return ['c1','c2','c3','c4'];
  }

  @override
  List<String> getColumnTypes() {
    return [Contract.TYPE_NUMBER,Contract.TYPE_NUMBER,Contract.TYPE_NUMBER,Contract.TYPE_NUMBER,];
  }

  @override
  String getTableName() {
    return 'table1';
  }
  @override
  List<int> getPrimaryColumnIndexes() {
    return [1];
  }

  @override
  String getAutoIncrementID(){
    return "id";
  }
}

Init database

LesSQL.initLesDB(new FooDB(), [new FooTable1(),new FooTable2()]);

Insert

LesTable and LesEntity must correspond one-to-one

class FooEntity1 extends LesEntity{

  String c1;
  int c2;
  int c3;
  int c4;

  FooEntity1(this.c1,this.c2,this.c3,this.c4);

  @override
  List getValues() {
    return [c1,c2,c3,c4];
  }
}

Random random = new Random();
FooEntity1 entity1 = new FooEntity1(random.nextInt(10000).toString(),
                     random.nextInt(10000), 
                     random.nextInt(10000), 
                     random.nextInt(10000));
LesSQL.insert(new FooTable1(), entity1.getValues()).then(_updateDes);

License #

   Copyright 2017 Qinglian.Zhang

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

[0.0.1-alpha] - In developing.

  • In developing.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:lessql/lessql.dart';
import 'dart:math';


class FooDB extends LesDB{

  @override
  String getName() {
    return 'foo_db';
  }

  @override
  int getVersion() {
    return 1;
  }

}

class FooTable1 extends LesTable{

  @override
  List<String> getColumnNames() {
    return ['c1','c2','c3','c4'];
  }

  @override
  List<String> getColumnTypes() {
    return [Contract.TYPE_STRING,Contract.TYPE_NUMBER,Contract.TYPE_NUMBER,Contract.TYPE_NUMBER,];
  }

  @override
  String getTableName() {
    return 'table1';
  }
  @override
  int getPrimaryColumnIndex() {
    return -1;
  }

  @override
  String getAutoIncrementID(){
    return "id";
  }
}

class FooEntity1 extends LesEntity{

  String c1;
  int c2;
  int c3;
  int c4;

  FooEntity1(this.c1,this.c2,this.c3,this.c4);

  @override
  List getValues() {
    return [c1,c2,c3,c4];
  }
}

class FooTable2 extends LesTable{

  @override
  List<String> getColumnNames() {
    return ['c1','c2',];
  }

  @override
  List<String> getColumnTypes() {
    return [Contract.TYPE_NUMBER,Contract.TYPE_STRING];
  }

  @override
  String getTableName() {
    return 'table2';
  }

  @override
  int getPrimaryColumnIndex() {
    return 0;
  }

  @override
  String getAutoIncrementID(){
    return "";
  }
}

void main() {
  runApp(new MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> implements LesSQLCallback{

  String des = "no opration";
  String ip = "";
  @override
  initState() {
    super.initState();
    LesSQL.initSelf(this);
    LesSQL.initLesDB(new FooDB(), [new FooTable1(),new FooTable2()]).then(_updateDes);
    _updateIP("确保你的手机和电脑连接同意路由器");
  }

  _insert(){
    Random random = new Random();
    FooEntity1 entity1 = new FooEntity1(random.nextInt(10000).toString(), random.nextInt(10000), random.nextInt(10000), random.nextInt(10000));
    LesSQL.insert(new FooTable1(), entity1.getValues()).then(_updateDes);
  }

  _updateDes(String str){
    setState(()=>des = str);
  }
  
  _updateIP(String str){
    setState(()=>ip = str);
  }
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(
          title: new Text('Plugin example app')
        ),
        body: new Center(
          child: new Column(children: <Widget>[
            new Text(ip,style: new TextStyle(fontSize: 20.0,color:Colors.black),),
            new Text(des),
            new RaisedButton(onPressed: _insert, child:  new Text("insert",style: new TextStyle(color: Colors.black,fontSize: 20.0),))
          ],)
        )
      )
    );
  }
  @override
  initDBIP(String ipAddress) {
    _updateIP(ipAddress);
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  lessql: ^0.0.1-alpha

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

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Analysis issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://dart.dev/dart-2#migration.

Maintenance issues and suggestions

Make sure dartdoc successfully runs on your package's source files. (-10 points)

Dependencies were not resolved.