krak/static-seed
Composer 安装命令:
composer require krak/static-seed
包简介
Powerful Seeding for static data.
README 文档
README
Static Seed provides a way to manage lookup table data in a reliable and maintainable away. Obviating the need for complex migration files or custom synchronization scripts, static seed allows you to define your table information in JSON and import/export into and from your database.
Installation
Install with composer at krak/static-seed
Usage
<?php use Krak\StaticSeed; const SEED_DIR = __DIR__ . '/path/to/seed/dir'; /** Setup the export tables */ function export(StaticSeed\Export $export) { $export->export([ new StaticSeed\Table('colors', 'tuple'), new StaticSeed\Table('color_sets', 'struct'), StaticSeed\Table::createJoin('color_sets_colors', 'color_set_id', [ 'color_set_id' => ['table' => 'color_sets', 'field' => 'slug'], 'color_id' => ['table' => 'colors', 'field' => 'slug'], ]) ], SEED_DIR); } function import(StaticSeed\Import $import) { $import->import(SEED_DIR); } function usage($argv) { printf("usage: %s <export|import>\n", $argv[0]); return 1; } function main($argv) { if (count($argv) <= 1) { exit(usage($argv)); } $conn = myDoctrineDbalConnection(); if ($argv[1] == 'export') { export(new StaticSeed\Export($conn)); } else if ($argv[1] == 'import') { import(new StaticSeed\Import($conn)); } else { exit(usage($argv)); } } main($argv);
Exporting will generate a set of files that look like this:
- colors.json
- colors_sets.json
- colors_sets_colors.json
colors.json:
{
"name": "colors",
"row_type": "tuple",
"type": "normal",
"fields": ["id", "name", "slug", "hex", "sort", "type"],
"rows": [
[1, "Red", "red", "#ff0000", 0, "normal"],
[2, "Green", "green", "#00ff00", 0, "normal"],
[3, "Blue", "blue", "#0000ff", 0, "normal"],
]
}
color_sets.json:
{
"name": "color_sets",
"row_type": "struct",
"type": "normal",
"fields": ["id", "name", "slug"],
"rows": [
{"id": 1, "name": "Color Set 1", "slug": "color-set-1"},
{"id": 1, "name": "Color Set 2", "slug": "color-set-2"}
]
}
color_sets_colors.json:
{
"name": "color_sets_colors",
"type": "join",
"row_type": "tuple",
"index_by": "color_set_id",
"fields": [
"color_set_id",
"color_id"
],
"map_id": {
"color_set_id": {
"table": "color_sets",
"field": "slug"
},
"color_id": {
"table": "colors",
"field": "slug"
}
},
"rows": {
"color-set-1": [
"red",
"green",
],
"color-set-2": [
"green",
"blue"
]
}
}
Symfony Installation
Register the following in your config/bundles.php to install the symfony bundle.
Krak\StaticSeed\Bridge\Symfony\StaticSeedBundle::class => ['all' => true],
krak/static-seed 适用场景与选型建议
krak/static-seed 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 364 次下载、GitHub Stars 达 0, 最近一次更新时间为 2017 年 08 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「database」 「fixtures」 「seed」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 krak/static-seed 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 krak/static-seed 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 krak/static-seed 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
Advanced seeding for laravel framework
Export your database quickly and easily as a Laravel Migration and all the data as a Seeder class.
Testing object factory for PHP
Testing object factory for PHP
Store your language lines in the database, yaml or other sources
统计信息
- 总下载量: 364
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-08-12