z0s / database
Database layer based on MongoDB. Kinda like Eloquent, but not
1.0.2
2022-02-16 12:58 UTC
Requires
- php: >=8.0
- ext-mongodb: *
- illuminate/collections: ^9.1
- mongodb/mongodb: ^1.11
Requires (Dev)
- roave/security-advisories: dev-latest
This package is not auto-updated.
Last update: 2024-11-21 23:57:16 UTC
README
Installation
You can include it in your project using: composer require z0s/database
Requirements
- PHP8.0 or higher
- MongoDB
Collection example
<?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'];
}
This collection can then be loaded like so..
$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);
or let your container manage loading things..