minnis/medoo-plus 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

minnis/medoo-plus

Composer 安装命令:

composer require minnis/medoo-plus

包简介

Medoo+, a wrapper to bring even more power to catfan/medoo - the lightweight PHP database framework to accelerate development

README 文档

README

A wrapper to bring even more power to catfan/medoo

the lightweight PHP database framework to accelerate development

Install

The package can be installed using composer:

composer require minnis/medoo-plus

Usage

This package extends catfan/medoo.

It is a drop-in replacement, just change your Medoo\Medoo namespaces to MINNIS\Medoo\Medoo

Medoo+

Improvements:

  • (mysql/mariadb) Connection option ATTR_EMULATE_PREPARES is now default set to false. Integer columns will now return integers instead of strings.
  • Mapping (data/column return types) of fetched data
  • \DateTime as return type on date/datetime/timestamp columns
  • Constants to map return types
  • Minor speed improvement

MAPS! (return type mapping)

Medoo has return type support by adding its type to the column name, like: `'is_active [Bool]'`.

In many cases this works fine but this method has a few drawbacks. These are solved by using a resultmap.

To use a resultmap add MAP (all uppercase) to the $where parameter on the select() or get() method, just like LIMIT, ORDER, etc:

$database->select('table', $columns, [
    'LIMIT' => 10,
    'MAP'   => [
        'column_name'  => Medoo::RETURN_BOOL,
        'other_column' => Medoo::RETURN_DATETIME,
    ],   
]);

Benefits

  • Mapping on wildcard * selects
  • Clean column names in $columns arrays
  • The contents of MAP array can by set by a single variable (easy re-usage)
  • Constants for autocompletion in your IDE
  • A new return type: DateTime object

DateTime

Getting strings from a Date, Datetime or Timestamp column serve little purpose. In most cases you will propably use the value to create a \DateTime object.

Now you can simply map it as return type using Medoo::RETURN_DATETIME.

This return type can be used on date, datetime, timestamp columns, as well on every column returning date[time] using yyyy-mm-dd [hh:mm:ss] notation or a numeric value (unix timestamp).

false (boolean) is returned if the source value is: null, false, an empty string, 0, '0000-00-00', '0000-00-00 00:00:00' and when the DateTime object could not be created due to a invalid value.

Example

<?php

use MINNIS\Medoo\Medoo;

require_once __DIR__ . '/../vendor/autoload.php';

$database = new Medoo(/* see medoo docs for details */);

// Default
$default_medoo = $database->select('users', [
    'username',
    'is_active',
    'signup_date',
], [
    'user_id' => 50,
]);

var_dump($default_medoo);

array(1) {
  [0] =>
  array(3) {
    'username' =>
    string(3) "foo"
    'is_active' =>
    string(1) "1"
    'signup_date' =>
    string(10) "2025-06-01"
  }
}

// Using MAP
$medoo_plus = $database->select('users', [
    'username',
    'is_active',
    'signup_date',
], [
    'user_id' => 50,
    'MAP'     => [
      'is_active'   => Medoo::RETURN_BOOL,
      'signup_date' => Medoo::RETURN_DATETIME,
    ]
]);

var_dump($medoo_plus);

array(1) {
  [0] =>
  array(3) {
    'username' =>
    string(3) "foo"
    'is_active' =>
    bool(true)
    'signup_date' =>
    class DateTime#1 (3) {
      public $date =>
      string(26) "2025-06-01 00:00:00.000000"
      public $timezone_type =>
      int(3)
      public $timezone =>
      string(16) "Europe/Amsterdam"
    }
  }
}

License

This package is under the MIT license.

Documentation

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-06-01

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固