Download the PHP package lin-orm/lite without Composer

On this page you can find all versions of the php package lin-orm/lite. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package lite

lite PHP ORM 文档

ORM,目前仅实现了MySQL部分,通过注解定义模型,支持查询、增删改、关联预加载、自动建表迁移。

版本选择

版本 PHP 要求 注解语法
v2.x ≥ 8.0 #[Attribute] 原生属性
v1.x ≥ 5.4 @Attribute PHPDoc 注解

Composer 会根据你的 PHP 版本自动安装对应版本。

目录


注解属性

所有注解位于 Lin\Lite\attr 命名空间。

两种语法

PHP 8.0+(v2.x):使用原生 #[Attribute] 语法:

PHP 5.4+(v1.x):使用 PHPDoc @属性名 语法,参数用 key: value 逗号分隔:

注意:多个注解换行写,每个 @注解 一行。参数格式 key: value,字符串用单引号或双引号包裹。

表注解(类级别)

注解 作用 参数
Table 定义表信息 name(表名), engine, charset, collation, comment

列注解(属性级别)

注解 作用 参数
Type SQL 类型 type, length, scale
Comment 列注释 comment
PrimaryKey 主键 无参数
AutoIncrement 自增 无参数
DefaultValue 默认值 value
Index 普通索引 name(可选,默认自动生成)
Json JSON 自动转换 无参数,写入 encode,读出 decode
ForeignKey 外键 table(引用表), column: 'id', onDelete, onUpdate

时间自动填充

注解 作用
CreatedAt INSERT 时如果为 null,自动填充当前时间(Y-m-d H:i:s)
UpdatedAt INSERT/UPDATE 时始终填充当前时间

权限注解(默认允许)

加了即禁止对应操作:

注解 作用
DisableRead 查询时跳过赋值
DisableCreate INSERT 时跳过该字段
DisableUpdate UPDATE 时跳过该字段
DisableMigrate 迁移/建表时不生成该列

关联注解

注解 作用 参数
BelongsTo BelongsTo(我方存外键) model 关联模型类
HasOne HasOne(对方存外键,一对一) model 关联模型类
HasMany HasMany(对方存外键,一对多) model 关联模型类

完整模型示例(PHP 8.0+)

完整模型示例(PHP 5.4+)


创建实例


查询

条件

排序、分页、限制

选择字段、JOIN、GROUP、HAVING

执行查询

结果都是通过引用返回,链式调用最后一步是赋值。


插入更新

保存(自动判断插入/更新)

插入

更新

唯一性检查


删除


关联预加载

关系说明

类型 外键位置 示例
BelongsTo 我方表 配置 属于 一种类型 → $config_type_id 加 #[BelongsTo(ConfigType::class)]
HasOne 对方表 类型 有一个 配置 → $config 加 #[HasOne(Config::class)]
HasMany 对方表 类型 有多个 配置 → $configs 加 #[HasMany(Config::class)]

使用方式


表迁移

根据模型注解自动创建/增量同步表结构。

注意:外键依赖要求先同步被引用的表,再同步引用表。

迁移策略


原生 SQL

通过 DB 上的静态方法,直接执行原生 SQL:


数据库连接

初始化数据库连接

默认使用 Conn::init(MySQLi 实现)初始化连接,应当在应用启动时调用,也可切换为自定义连接:


自定义数据库连接

ConnInterface 定义了连接需要实现的接口:

默认使用 Conn(MySQLi 实现),也可切换为自定义连接:

替换后所有 ORM 操作都会走自定义连接,不同数据库适配只需实现这个接口。


事务


Scope 复用

复用通用查询逻辑:


调试


回调钩子

模型中可以定义这些方法,会在对应时机调用:


All versions of lite with dependencies

PHP Build Version
Package Version
Requires php Version >=8.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package lin-orm/lite contains the following files

Loading the files please wait ...