定制 drago-ex/database 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

drago-ex/database

最新稳定版本:v2.0.1

Composer 安装命令:

composer require drago-ex/database

包简介

Connecting to database for Nette Framework

README 文档

README

Simple recurring questions.

License: MIT PHP version Tests Coding Style CodeFactor Coverage Status

Requirements

  • PHP >= 8.3
  • Nette Framework
  • dibi
  • Composer

Knowledge

Installation

composer require drago-ex/database 

Basic Model Example

#[Table('table_name', 'primary_key')] class Model { use Database; }

Common Queries

Reading records from a table:

$this->model->read('*');

Find records by column name:

$this->model->find('column, 'value');

Get a record by ID:

$this->model->get(1);

Delete a record by column name:

$this->model->delete('column, 'value');

Save records as an array (update if id is provided):

$this->model->save(['column' => 'value']);

Using Entities

class SampleEntity extends Drago\Database\Entity { public const Table = 'name'; public const PrimaryKey = 'id'; public ?int $id = null; public string $sample; }

Use the entity in a model:

#[From(SampleEntity::Table, SampleEntity::PrimarKey)] class Model { use Database; }

Fetch records as objects:

$row = $this->model->find('id', 1)->record(); // Accessing properties echo $row->id; echo $row->sample;

Save Entity Records

To save entity data (update record if id is present):

$entity = new SampleEntity; $entity->id = 1; $entity->sample = 'sample'; $this->save($entity);

Advanced Features

Entity Class for Database Mapping

You can use a custom entity class with database mapping:

/** @extends Database<SampleEntity> */ #[From(SampleEntity::Table, SampleEntity::PrimaryKey, class: SampleEntity::class)] class Model { use Database; } // Fetch records directly as objects $row = $this->model->find('id', 1)->record(); // Access the object's properties echo $row->id; echo $row->sample; // Fetch all records $allRecords = $this->model->read('*')->recordAll();

Entity Generation

For automatic entity generation, consider using the Drago Generator tool: https://github.com/drago-ex/generator

统计信息

  • 总下载量: 4.75k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 3
  • 依赖项目数: 6
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固