Skip to content

Latest commit

 

History

History
162 lines (128 loc) · 2.52 KB

README_ZH.md

File metadata and controls

162 lines (128 loc) · 2.52 KB

sqlite_utils

Pub

Flutter sqflite plugin 帮助扩展类.

English

安装方法

Install

APIs

初始化连接

 var db = SqliteUtils(settings: {
      'database': 'loop.db',
      'tableMap': {
          'table1':'id INTEGER PRIMARY KEY, nickname TEXT, telphone TEXT, createTime INTEGER, updateTime INTEGER',
          'table2': 'id INTEGER PRIMARY KEY, title TEXT, titleId INTEGER',
      },
      'version': 1,
    });

query

var row = await db
    .query('select * from table id=1');
print(row);
// db.close();

getOne

查询一条数据

var row = await db.getOne(
  table: 'table',
  fields: '*',
  //group: 'name',
  //having: 'name',
  //order: 'id desc',
  //limit: 10,//10 or '10 ,100'
  where: {'email': '[email protected]'},
);
print(row);

getAll

查询多条数据

var row = await db.getAll(
  table: 'table',
  fields: '*',
  //group: 'name',
  //having: 'name',
  //order: 'id desc',
  //limit: 10,//10 or '10 ,100'
  where: {
    'email': '[email protected]',
    //'id': ['between', 0, 1], //or ['between', [0, 1]]
    //'id': ['notbetween', 0, 2],//or ['notbetween', [0, 1]]
    //'id': ['in', [1,2,3]],
    //'id': ['notin', [1,2,3]],
    //'email': ['=', '[email protected]'],
    //'news_title': ['like', '%name%'],
    //'user_id': ['>', 1],

  },
);
print(row);

insert

增加一条数据

await db.insert(
  table: 'table',
  insertData: {
    'telphone': '+113888888888',
    'create_time': 1620577162252,
    'update_time': 1620577162252,
  },
);

insertAll

增加多条数据

 await db.insertAll(
  table: 'table',
  insertData: [
      {
        'telphone': '13888888888',
        'create_time': 1111111,
        'update_time': 12121212,
        'email': '[email protected]'
      },
      {
        'telphone': '13881231238',
        'create_time': 324234,
        'update_time': 898981,
        'email': '[email protected]'
      }
]);

update

更新数据

await db.update(
  table: 'table',
  updateData:{
    'telphone': '1231',
    'create_time': 12,
    'update_time': 12121212,
    'email': '[email protected]'
  },
  where:{
  'id':1,
});

delete

删除数据

await db.delete(
  table:'table',
  where: {'id':1}
);

count

统计数据

await db.count(
  table: 'table',
  fields: '*',
  //group: 'name',
  //having: 'name',
  //debug: false,
);