z0s/database

基于MongoDB的数据库层。有点像Eloquent,但不是

维护者

详细信息

gitlab.com/z0s/database

源代码

问题

安装: 12

依赖: 0

建议者: 0

安全: 0

星星: 1

分支: 0

类型:composer-package

1.0.2 2022-02-16 12:58 UTC

This package is not auto-updated.

Last update: 2024-09-26 23:15:54 UTC


README

安装

您可以通过以下方式将其包含到项目中:composer require z0s/database

要求

  1. PHP8.0或更高版本
  2. MongoDB

集合示例

<?php

namespace z0s\Models;

use z0s\Database\Collection;

class Users extends Collection
{
    /** @var string Name of collection in database */
    public string $collectionName = 'users';

    /** @var string Name of database that the collection is stored in */
    public string $databaseName = 'app';

    /** @var string Primary index key */
    public string $indexField = 'email';

    /** @var string[] $hiddenFields Fields to hide from output (ie. Password hash, email etc.) */
    public array $hiddenFields = [];

    /** @var string[] $required Fields required to insert data to model (ie. email, password hash, etc.) */
    public array $required = ['email', 'password', 'firstName', 'lastName'];
}

这个集合可以按如下方式加载..


$connection = new \z0s\Database\Connection([
        [
            'host' => 'mongodb://127.0.0.1',
            'port' => 27017
        ]
    ],
    [
        'options' => [
            'connectTimeoutMS' => 30000,
            'socketTimeoutMS' => 30000,
            'serverSelectionTimeoutMS' => 30000
        ],
        'typeMap' => [
            'root' => 'object',
            'document' => 'object',
            'array' => 'object',
        ],
        'db' => 'z0s'
    ]
);

$users = new \z0s\Models\Users($connection);

或者让您的容器管理加载内容..