Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/drago-ex/database
:floppy_disk: Simple recurring questions. (@nette)
https://github.com/drago-ex/database
database dibi nette
Last synced: about 2 months ago
JSON representation
:floppy_disk: Simple recurring questions. (@nette)
- Host: GitHub
- URL: https://github.com/drago-ex/database
- Owner: drago-ex
- License: mit
- Created: 2015-10-16T06:58:42.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2024-04-11T11:33:28.000Z (9 months ago)
- Last Synced: 2024-04-24T03:21:50.222Z (9 months ago)
- Topics: database, dibi, nette
- Language: PHP
- Homepage:
- Size: 44.9 MB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license.md
Awesome Lists containing this project
README
## Drago Database
Simple recurring questions.[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://raw.githubusercontent.com/drago-ex/database/master/license.md)
[![PHP version](https://badge.fury.io/ph/drago-ex%2Fdatabase.svg)](https://badge.fury.io/ph/drago-ex%2Fdatabase)
[![Tests](https://github.com/drago-ex/database/actions/workflows/tests.yml/badge.svg)](https://github.com/drago-ex/database/actions/workflows/tests.yml)
[![Coding Style](https://github.com/drago-ex/database/actions/workflows/coding-style.yml/badge.svg)](https://github.com/drago-ex/database/actions/workflows/coding-style.yml)
[![CodeFactor](https://www.codefactor.io/repository/github/drago-ex/database/badge)](https://www.codefactor.io/repository/github/drago-ex/database)
[![Coverage Status](https://coveralls.io/repos/github/drago-ex/database/badge.svg?branch=master)](https://coveralls.io/github/drago-ex/database?branch=master)## Technology
- PHP 8.1 or higher
- composer## Knowledge
- [Dibi - smart database layer for PHP](https://github.com/dg/dibi)## Installation
```
composer require drago-ex/database
```## Use
```php
#[Table('table', 'id')]
class Model {}
```## Basic queries in the Repository
Get records from table.
```php
$this->model->table();
```Search for a record by column name in the table.
```php
$this->model->table('email = ?', '[email protected]');
```Search for a record by id.
```php
$this->model->get(1);
```Delete a record from the database.
```php
$this->model->remove(1);
```Save record (the update will be performed if a column with id is added).
```php
$this->model->put(['column' => 'record']);
```## Use of entity
```php
class SampleEntity extends Drago\Database\Entity
{
public const Table = 'table';
public const PrimaryKey = 'id';public ?int $id = null;
public string $sample;
}
```Basic repository.
```php
#[Table(SampleEntity::Table, SampleEntity::PrimarKey)]
class Repository {}
```Use of an entity in a repository.
```php
function find(int $id): array|SampleEntity|null
{
return $this->get($id)->fetch();
}
```Reading data.
```php
$row = $this->find(1);
echo $row->id;
echo $row->sample;
```Save records across an entity (to update the record we add id).
```php
$entity = new SampleEntity;
$entity->id = 1;
$entity->sample = 'sample';$this->save($entity);
```The save method saves the record to the database.
```php
function save(SampleEntity $entity): Result|int|null
{
return $this->put($entity);
}
```## Tips
You can also use entities and have them generated. [https://github.com/drago-ex/generator](https://github.com/drago-ex/generator)