承接 minifast/minifast-orm 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

minifast/minifast-orm

Composer 安装命令:

composer require minifast/minifast-orm

包简介

A little ORM, very simple to use and ultra fast

README 文档

README

MiniFast ORM is a very little Object-Relational Mapping system. It will be usefull for little web projects where you don't want to spend all your time writting SQL queries.

Documentation

First of all

You need to create a .xml file containing your databse scheme. All supported types and the syntax will be available soon. Example:

<?xml version="1.0" encoding="UTF-8"?>
<database name="main">
    <table name="user">
        <column name="id" type="int" primaryKey="true" autoIncrement="true"/>
        <column name="pseudo" type="varchar" size="50"/>
        <column name="email" type="varchar" size="139"/>
        <column name="password" type="varchar" size="128"/>
        <column name="admin" type="boolean" default="0"/>
        <column name="image" type="text"/>
        <column name="newsletter" type="boolean" default="true"/>
        <column name="email_public" type="boolean" default="true"/>
    </table>
    <table name="category">
        <column name="id" type="int" primaryKey="true" autoIncrement="true"/>
        <column name="name" type="varchar" size="20"/>
    </table>
    <table name="topic">
        <column name="id" type="int" primaryKey="true" autoIncrement="true"/>
        <column name="category" type="int" required="true"/>
        <foreign-key foreign-table="category">
            <reference local="category" foreign="id"/>
        </foreign-key>
    </table>
</database>

Install

Install MiniFast with Composer by adding it to the composer.json file:

{
    "require": {
        "minifast/minifast-orm": "^1"
    }
}

There is an installer included in MiniFast that will create classes for you based on your xml schema. Assuming you are in your website root directory, execute it like this:

$ php vendor/minifast/minifast-orm/init.php /path/to/schema.xml

There will be no input if there is no error.

How to use

After running the installer, an autoloader has been created. Set up the MySQL host, user and password (defaults are localhost, root and root) in vendor/itechcydia/minifast-orm/src/minifast/Base.php and vendor/itechcydia/minifast-orm/src/minifast/BaseQuery.php __construct() methods.

An autoload.php file has been created by Composer and you need to include it in order to use MiniFast. Assuming you have the same schema.xml than the one above, you will find some examples below:

INSERT

<?php
$user = new User();
$user
    ->setPseudo('iTechCydia')
    ->setEmail('email@server.com')
    ->setPassword(hash('whirlpool', 'theUserSecretPassword'))
    ->setDate(time())
    ->save();

This will create the SQL query and execute it.

SELECT

Select 10 users starting after the third.

<?php
$user = new UserQuery::create()
    ->limit(10)
    ->offset(3)
    ->findAll();

Only the user 23.

<?php
$user = new UserQuery::create()
    ->findPK(23);

Users 23, 24 and 25.

<?php
$user = new UserQuery::create()
    ->findPKs([23, 24, 25]);

User where pseudo is iTechCydia.

<?php
$user = new UserQuery::create()
    ->findByPseudo('iTechCydia')
    ->find();

UPDATE

Update user 23 and set newsletter to true, email_public to false and email to email2@server.com.

<?php
$user = UserQuery::create()
    ->filterById(23)
    ->setNewsletter(true)
    ->setEmailPublic(false)
    ->setEmail('email2@server.com')
    ->save(); // Don't forget to save!

DELETE

Delete all from user table (you need to set the first parameter to true to avoid any mistake)

<?php
$user = UserQuery::create()
    ->delete(true);

Delete specific users using filters

$user = UserQuery::create()
    ->filterByNewsletter(false) // bad users :p
    ->delete();

统计信息

  • 总下载量: 20
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 3
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-09-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固