更新记录

1.0.0(2020-04-04)


平台兼容性

特性:类似于thinkPHP的orm

1.获取数据库操作对象

var sql=new SQL(); 或者 var sql=D();

2.链式说明

/**

  • Class SQL
  • @package js
  • @method Query table(string $table) static 指定数据表(含前缀)
  • @method Query name(string $name) static 指定数据表(不含前缀)
  • @method Query where(mixed $field, string $op = null, mixed $condition = null) static 查询条件
  • @method Query join(mixed $join, mixed $condition = null, string $type = 'INNER') static JOIN查询
  • @method Query union(mixed $union, boolean $all = false) static UNION查询
  • @method Query limit(mixed $offset, integer $length = null) static 查询LIMIT
  • @method Query order(mixed $field, string $order = null) static 查询ORDER
  • @method Query cache(mixed $key = null , integer $expire = null) static 设置查询缓存
  • @method mixed value(string $field) static 获取某个字段的值
  • @method array column(string $field, string $key = '') static 获取某个列的值
  • @method Query view(mixed $join, mixed $field = null, mixed $on = null, string $type = 'INNER') static 视图查询
  • @method mixed find(mixed $data = null) static 查询单个记录
  • @method mixed select(mixed $data = null) static 查询多个记录
  • @method integer insert(array $data, boolean $replace = false, boolean $getLastInsID = false, string $sequence = null) static 插入一条记录
  • @method integer insertGetId(array $data, boolean $replace = false, string $sequence = null) static 插入一条记录并返回自增ID
  • @method integer insertAll(array $dataSet) static 插入多条记录
  • @method integer update(array $data) static 更新记录
  • @method integer delete(mixed $data = null) static 删除记录
  • @method boolean chunk(integer $count, callable $callback, string $column = null) static 分块获取数据
  • @method mixed query(string $sql, array $bind = [], boolean $master = false, bool $pdo = false) static SQL查询
  • @method integer execute(string $sql, array $bind = [], boolean $fetch = false, boolean $getLastInsID = false, string $sequence = null) static SQL执行
  • @method Paginator paginate(integer $listRows = 15, mixed $simple = null, array $config = []) static 分页查询
  • @method mixed transaction(callable $callback) static 执行数据库事务
  • @method void startTrans() static 启动事务
  • @method void commit() static 用于非自动提交状态下面的查询提交
  • @method void rollback() static 事务回滚
  • @method boolean batchQuery(array $sqlArray) static 批处理执行SQL语句
  • @method string quote(string $str) static SQL指令安全过滤
  • @method string getLastInsID($sequence = null) static 获取最近插入的ID */

3.实例

3.1 增加

let data={name:"小米",sex:"1"} var _sql=D().table("tb_name").data(data).insert().exe(); SQL:insert tb_name(name,sex) value("小米","1")

3.2 删除

var _sql=D().table("tb_name").where("name=2").delegate().exe(); SQL:delete from tb_name where name=2

3.3 修改

let data={name:"小米",sex:"1"} var _sql=D().table("tb_name").where("name=2").update(data).exe(); SQL:update from tb_name set name="小米",sex=1 where name=2

3.4 查询

var _sql=D().table("tb_name").where("name=2").select().run(); SQL:select * from tb_name where name=2

4.注意

4.1 尾缀exe()和run()是有差别的,exe只执行及返回状态,run会返回查询列表及状态。 4.2 操作方式如同thinkPHP,笔者由于对其他功能实现未尝试多次使用,可能存在部分bug问题。 4.3 由于开发中该框架底层是基于plus提供的SQLite操作方法,如果需要迁移,请自行修改底层操作方法。 4.4 笔者想过基于此做数据模型,但精力有限,希望同志们补缺不足。

项目实例

let data={ name:"小米", sex:"男" } //增 this.title1=sql.table("tb_name").data(data).insert().getLastSql() //删 this.title2=sql.table("tb_name").where("id",1).delegate().getLastSql() //改 this.title3=sql.table("tb_name").data(data).update().getLastSql() //查 this.title4=sql.table("tb_name").where("name","xh").select().getLastSql() //链表查询 this.title5=sql.table("tb_name1").alias("tb_1").join("tb_name2","tb_2").where("name","xh").select().getLastSql() //组查询 this.title6=sql.table("tb_name").group("name").select().getLastSql()

隐私、权限声明

1. 本插件需要申请的系统权限列表:

添加sqlite模块

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

许可协议

MIT协议

使用中有什么不明白的地方,就向插件作者提问吧~ 我要提问