天天看點

ActiveRecord語言實作PHP、Python、Node.js

以下架構都實作了兩種查詢方式

Query Builder + ORM

Laravel

Eloquent ORM :

https://laravel.com/docs/7.x/eloquent

代碼示例

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

// 定義
class Flight extends Model
{
    //
}

// 使用
DB::table('users')->where('votes', '=', 100)->get();

$flight = App\Flight::where('number', 'FR 900')->first();      

ThinkPHP

文檔

https://www.kancloud.cn/manual/thinkphp5/135176

ThinkPHP7.0之後單獨拆開

ThinkORM: 

https://www.kancloud.cn/manual/think-orm/
<?php
namespace app\index\model;

use think\Model;

// 定義
class User extends Model
{
}

// 使用
Db::name('user')->where('id','>',10)->select();

// 或者
User::where('id','>',10)->select();      

Orator ORM

https://github.com/sdispater/orator
# 定義
class User(Model):
    pass

# 使用
db.table('users').where('age', '>', 25).get()

# 或者
users = User.where('votes', '>', 100).take(10).get()      

AdonisJs

Lucid models

https://adonisjs.com/docs/4.1/lucid
'use strict'

const Model = use('Model')
const Database = use('Database')

// 定義
class User extends Model {
}

// 使用
Database
      .table('users')
      .where('username', 'john')
      .first()


// 或者
const adults = await User
  .query()
  .where('age', '>', 18)
  .fetch()      

總結

目前(2020.3)的一些參數比較

架構 語言 最新版本 Github Star Github
PHP 7.x 58.1k
Node.js 5.0 7.9k
2.8k
Orator Python 0.9.9 1.1k

除了ThinkPHP有完整的中文文檔之外,其他架構都是英文的或翻譯版