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 StarGithub
LaravelPHP7.x58.1kGithub
AdonisJsNode.js5.07.9kGithub
ThinkPHPPHP5.02.8kGithub
OratorPython0.9.91.1kGithub

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

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值