diff --git a/README.md b/README.md index 936c08fbf9c52d6f7751acd4e3279697ab331807..1c83c7ae5318af33be035c71fba35510f02d984e 100644 --- a/README.md +++ b/README.md @@ -26,3 +26,85 @@ php -dxdebug.mode=debug -dxdebug.start_with_request=yes -dxdebug.client_host=lo 1.将"vendor/thinkcmf/cmf-install"文件夹删除; 2.最好执行"composer remove thinkcmf/cmf-install"删除! 另请对data/config/database.php文件做好备份,以防丢失! + +## Class Model + + * @method static $this scope(string|array $scope) static 查询范围 + * @method static $this where(mixed $field, string $op = null, mixed $condition = null) static 查询条件 + * @method static $this whereRaw(string $where, array $bind = [], string $logic = 'AND') static 表达式查询 + * @method static $this whereExp(string $field, string $condition, array $bind = [], string $logic = 'AND') static 字段表达式查询 + * @method static $this when(mixed $condition, mixed $query, mixed $otherwise = null) static 条件查询 + * @method static $this join(mixed $join, mixed $condition = null, string $type = 'INNER', array $bind = []) static JOIN查询 + * @method static $this view(mixed $join, mixed $field = null, mixed $on = null, string $type = 'INNER') static 视图查询 + * @method static $this with(mixed $with, callable $callback = null) static 关联预载入 + * @method static $this count(string $field = '*') static Count统计查询 + * @method static $this min(string $field, bool $force = true) static Min统计查询 + * @method static $this max(string $field, bool $force = true) static Max统计查询 + * @method static $this sum(string $field) static SUM统计查询 + * @method static $this avg(string $field) static Avg统计查询 + * @method static $this field(mixed $field, boolean $except = false, string $tableName = '', string $prefix = '', string $alias = '') static 指定查询字段 + * @method static $this fieldRaw(string $field) static 指定查询字段 + * @method static $this union(mixed $union, boolean $all = false) static UNION查询 + * @method static $this limit(mixed $offset, integer $length = null) static 查询LIMIT + * @method static $this order(mixed $field, string $order = null) static 查询ORDER + * @method static $this orderRaw(string $field, array $bind = []) static 查询ORDER + * @method static $this cache(mixed $key = null, integer|\DateTime $expire = null, string $tag = null) static 设置查询缓存 + * @method static mixed value(string $field, mixed $default = null) static 获取某个字段的值 + * @method static array column(string $field, string $key = '') static 获取某个列的值 + * @method static $this find(mixed $data = null) static 查询单个记录 + * @method static $this findOrFail(mixed $data = null) 查询单个记录 + * @method static Collection|$this[] select(mixed $data = null) static 查询多个记录 + * @method static $this get(mixed $data = null, mixed $with = [], bool $cache = false, bool $failException = false) static 查询单个记录 支持关联预载入 + * @method static $this getOrFail(mixed $data = null, mixed $with = [], bool $cache = false) static 查询单个记录 不存在则抛出异常 + * @method static $this findOrEmpty(mixed $data = null) static 查询单个记录 不存在则返回空模型 + * @method static Collection|$this[] all(mixed $data = null, mixed $with = [], bool $cache = false) static 查询多个记录 支持关联预载入 + * @method static $this withAttr(array $name, \Closure $closure = null) static 动态定义获取器 + * @method static $this withJoin(string|array $with, string $joinType = '') static + * @method static $this withCount(string|array $relation, bool $subQuery = true) static 关联统计 + * @method static $this withSum(string|array $relation, string $field, bool $subQuery = true) static 关联SUM统计 + * @method static $this withMax(string|array $relation, string $field, bool $subQuery = true) static 关联MAX统计 + * @method static $this withMin(string|array $relation, string $field, bool $subQuery = true) static 关联Min统计 + * @method static $this withAvg(string|array $relation, string $field, bool $subQuery = true) static 关联Avg统计 + * @method Paginator|$this paginate(int|array $listRows = null, int|bool $simple = false, array $config = []) static 分页 + +## DbManager + + * @method static \think\db\Query master() static 从主服务器读取数据 + * @method static \think\db\Query readMaster(bool $all = false) static 后续从主服务器读取数据 + * @method static \think\db\Query table(string $table) static 指定数据表(含前缀) + * @method static \think\db\Query name(string $name) static 指定数据表(不含前缀) + * @method static \think\db\Expression raw(string $value) static 使用表达式设置数据 + * @method static \think\db\Query where(mixed $field, string $op = null, mixed $condition = null) static 查询条件 + * @method static \think\db\Query whereRaw(string $where, array $bind = []) static 表达式查询 + * @method static \think\db\Query whereExp(string $field, string $condition, array $bind = []) static 字段表达式查询 + * @method static \think\db\Query when(mixed $condition, mixed $query, mixed $otherwise = null) static 条件查询 + * @method static \think\db\Query join(mixed $join, mixed $condition = null, string $type = 'INNER') static JOIN查询 + * @method static \think\db\Query view(mixed $join, mixed $field = null, mixed $on = null, string $type = 'INNER') static 视图查询 + * @method static \think\db\Query field(mixed $field, boolean $except = false) static 指定查询字段 + * @method static \think\db\Query fieldRaw(string $field, array $bind = []) static 指定查询字段 + * @method static \think\db\Query union(mixed $union, boolean $all = false) static UNION查询 + * @method static \think\db\Query limit(mixed $offset, integer $length = null) static 查询LIMIT + * @method static \think\db\Query order(mixed $field, string $order = null) static 查询ORDER + * @method static \think\db\Query orderRaw(string $field, array $bind = []) static 查询ORDER + * @method static \think\db\Query cache(mixed $key = null , integer $expire = null) static 设置查询缓存 + * @method static \think\db\Query withAttr(string $name,callable $callback = null) static 使用获取器获取数据 + * @method static mixed value(string $field) static 获取某个字段的值 + * @method static array column(string $field, string $key = '') static 获取某个列的值 + * @method static mixed find(mixed $data = null) static 查询单个记录 + * @method static mixed select(mixed $data = null) static 查询多个记录 + * @method static integer insert(array $data, boolean $replace = false, boolean $getLastInsID = false, string $sequence = null) static 插入一条记录 + * @method static integer insertGetId(array $data, boolean $replace = false, string $sequence = null) static 插入一条记录并返回自增ID + * @method static integer insertAll(array $dataSet) static 插入多条记录 + * @method static integer update(array $data) static 更新记录 + * @method static integer delete(mixed $data = null) static 删除记录 + * @method static boolean chunk(integer $count, callable $callback, string $column = null) static 分块获取数据 + * @method static \Generator cursor(mixed $data = null) static 使用游标查找记录 + * @method static mixed query(string $sql, array $bind = [], boolean $master = false, bool $pdo = false) static SQL查询 + * @method static integer execute(string $sql, array $bind = [], boolean $fetch = false, boolean $getLastInsID = false, string $sequence = null) static SQL执行 + * @method static \think\Paginator paginate(integer $listRows = 15, mixed $simple = null, array $config = []) static 分页查询 + * @method static mixed transaction(callable $callback) static 执行数据库事务 + * @method static void startTrans() static 启动事务 + * @method static void commit() static 用于非自动提交状态下面的查询提交 + * @method static void rollback() static 事务回滚 + * @method static boolean batchQuery(array $sqlArray) static 批处理执行SQL语句 + * @method static string getLastInsID(string $sequence = null) static 获取最近插入的ID \ No newline at end of file diff --git a/demotp6/tests/DemoTp6.php b/demotp6/tests/DemoTp6.php index 5bc043edd1114c70da71a8e647acee3ad5d71abe..f21dbeab61cfbb29bf18c84c6c644a092e32203f 100644 --- a/demotp6/tests/DemoTp6.php +++ b/demotp6/tests/DemoTp6.php @@ -40,7 +40,7 @@ class DemoTp6 extends TestCase{ var_dump($bb,$cc); } function test_select_user() { - $user = User::find(3); + $user = User::find(2); print User::class; print UserState::from($user->status)->label(); } @@ -56,12 +56,15 @@ class DemoTp6 extends TestCase{ // table方法必须指定完整的数据表名 - $app=App(); - $aa=$app->db->table('tp6_user')->find(2); - var_dump($aa); + // $app=App(); + // $aa=$app->db->table('tp6_user')->find(2); + // var_dump($aa); + // $aa=Db::table('tp6_user')->find(2); // var_dump($aa); + $aa=Db::table('tp6_user')->find(2); + var_dump($aa); // $app = app(); // $user = new User();