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
Laravel PHP 7.x 58.1k Github
AdonisJs Node.js 5.0 7.9k Github
ThinkPHP PHP 5.0 2.8k Github
Orator Python 0.9.9 1.1k Github

除了ThinkPHP有完整的中文文档之外,其他框架都是英文的或翻译版

发布了1446 篇原创文章 · 获赞 396 · 访问量 139万+

猜你喜欢

转载自blog.csdn.net/mouday/article/details/104882837