Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zqhong/fastd-eloquent
https://github.com/zqhong/fastd-eloquent
db eloquent fastd
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/zqhong/fastd-eloquent
- Owner: zqhong
- License: mit
- Created: 2017-06-29T08:29:48.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-10-25T02:58:38.000Z (about 2 years ago)
- Last Synced: 2023-11-20T15:02:33.477Z (about 1 year ago)
- Topics: db, eloquent, fastd
- Language: PHP
- Size: 28.3 KB
- Stars: 10
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fastD Eloquent
使用 Eloquent 替换 fastD 自带的 [Medoo](https://medoo.in/)## 安装
```bash
$ composer require -vvv zqhong/fastd-eloquent
```## 配置
修改配置文件 `config/app.conf`,添加 `EloquentServiceProvider`,如下:
```php
[
\ServiceProvider\EloquentServiceProvider::class,
],
];
```修改配置文件 `.env.yml`,添加如下信息:
```yaml
database:
default:
adapter: db_adapter
name: db_name
host: db_host
user: db_username
pass: db_password
charset: db_charset
port: db_port
prefix: db_prefix
```其中,`driver` 的可选值为:`mysql`、`pgsql`、`sqlite` 和 `sqlsrv`。
## 直接使用
```php
table('demo')
->insert([
'content' => 'hello world',
]);// read
// 参数一可省略,默认值为 default
Manager::connection('default')
->table('demo')
->where('id', 1)
->where('created_at', '<=', time())
->get([
'id',
'content',
]);// update
Manager::connection('default')
->table('demo')
->where('id', 1)
->update([
'content' => 'hello 2',
]);// delete
Manager::connection('default')
->table('demo')
->where('id', 1)
->delete();```
## 配置 Model 使用
```php
get()
->toArray();
}
}
```## 分页
### 分页的简单使用
```php
paginate($perPage, $columns, $pageName);
$data = $paginator->toArray();// 注:page 参数(当前页)会自动从 $_GET 或 $_POST 中的 page 参数自动获取,不需要单独设置。
// 参考代码
//LengthAwarePaginator::currentPageResolver(function () {
// return (int)Arr::get(array_merge($_GET, $_POST), 'page', 1);
//});
```## 其他资源
如果你对在其他框架中使用 Eloquent 感兴趣,请参考 Slim 的这篇文章 - [Using Eloquent with Slim](https://www.slimframework.com/docs/cookbook/database-eloquent.html)。如果你对 Eloquent 不熟悉,请阅读下面的资料。
* [Laravel - Database: Query Builder](https://laravel.com/docs/5.4/queries)
* [Laravel - Database: Pagination](https://laravel.com/docs/5.4/pagination)
* [Laravel - Eloquent: Getting Started](https://laravel.com/docs/5.4/eloquent)
* [Laravel - Eloquent: Collections](https://laravel.com/docs/5.4/eloquent-collections)