bubu-framework/database

数据库通信(bubu 框架)

V1.2.7 2023-05-20 14:45 UTC

This package is auto-updated.

Last update: 2024-09-20 18:08:24 UTC


README

使用 composer 安装

$ composer require bubu-framework/database

配置

遵循 .env.example 语法

用法

创建表

调用 Database CreateTable 常量以创建表,设置它并调用 execute 函数以创建表。调用 addColumn 方法以创建列并将其添加到表中。

  • 示例:

    Database::createTable('test')->addColumn(
        Database::createColumn('col1')
        ->type(CreateColumn::INT)
        ->size(10)
        ->defaultValue(30)
        ->comments("It's ok")
        ->notNull()
        )
        ->addColumn(
            Database::createColumn('id')
                ->type(CreateColumn::INT)
                ->size(11)
                ->autoIncrement()
        )
        ->addIndex([
            'type' => 'primary',
            'columns' => ['id'],
            'name' => 'primaryKey'
        ])
        ->addIndex([
            'type' => CreateTable::UNIQUE_INDEX,
            'columns' => ['col1', 'id'],
            'name' => 'uniqueKey'
        ])
        ->execute();