{"id":36975808,"url":"https://github.com/liryan/dbfiller","last_synced_at":"2026-01-13T22:06:14.225Z","repository":{"id":62517645,"uuid":"86044576","full_name":"liryan/dbfiller","owner":"liryan","description":"基于Laravel / Lumen的组件，给数据库自动生成测试数据 ","archived":false,"fork":false,"pushed_at":"2017-04-02T03:11:50.000Z","size":77,"stargazers_count":7,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-07-13T05:19:00.708Z","etag":null,"topics":["bot","database","lavavel","mysql","performance-testing"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/liryan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-24T08:25:15.000Z","updated_at":"2017-03-31T09:10:53.000Z","dependencies_parsed_at":"2022-11-02T13:17:31.845Z","dependency_job_id":null,"html_url":"https://github.com/liryan/dbfiller","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/liryan/dbfiller","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liryan%2Fdbfiller","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liryan%2Fdbfiller/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liryan%2Fdbfiller/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liryan%2Fdbfiller/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/liryan","download_url":"https://codeload.github.com/liryan/dbfiller/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liryan%2Fdbfiller/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28402160,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-13T14:36:09.778Z","status":"ssl_error","status_checked_at":"2026-01-13T14:35:19.697Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bot","database","lavavel","mysql","performance-testing"],"created_at":"2026-01-13T22:06:13.351Z","updated_at":"2026-01-13T22:06:14.207Z","avatar_url":"https://github.com/liryan.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"安装说明:\n=\n\n`composer require 'liryan/dbfiller' 'dev-master'`\n\n使用说明\n=\n在config/app.php中添加provider\n```php\nproviders=[\n    ...\n    Dbfiller\\DBFillerProvider::class,\n],\n```\n\n在Lumen框架中，修改bootstrap/app.php\n```php\n...\n$app-\u003eregister(Dbfiller\\DBFillerProvider::class);\n```\n\n生成配置文件\n=\nlaravel运行命令，生成config/dbfiller.php\n\n`php artisan vendor:publish`\n\nLumen中生成配置文件复制到项目config目录，不存在就新建\n\n`cp vendor/liryan/dbfiler/src/config/dbfiller.php config/`\n\n\n根据数据库修改此文件\n然后运行\n\n`php artisan mysql.filler`\n\n测试format\n\n`php artisan mysql.filler 'format' --count=1`\n\n配置文件说明\n=\n```php\n\u003c?php\nreturn[\n    '表1'=\u003e\n    [\n        'total'=\u003e'要生成多少数据',\n        'key'=\u003e'此表的主键字段名字,默认为id',\n        'define'=\u003e[\n            '字段名1'=\u003e['format'=\u003e'格式说明','from'=\u003e'引用数据']  \n            '字段名2'=\u003e['format'=\u003e'格式说明','from'=\u003e'引用数据']  \n            ...\n        ]\n    ],\n    '表2'=\u003e\n    [\n        'total'=\u003e'要生成多少数据',\n        'key'=\u003e'此表的主键字段名字,默认为id',\n        'define'=\u003e[\n            '字段名1'=\u003e['format'=\u003e'格式说明','from'=\u003e'引用数据']  \n            '字段名2'=\u003e['format'=\u003e'格式说明','from'=\u003e'引用数据']  \n            //不写字段，则会按照数据库中定义的数据类型自动生成\n            ...\n        ]\n    ],\n    ...\n];\n```\n\n格式说明\n=\n字符串格式：[%|#][max-min][u/d/s/f/p]\n\n解释\n    %   随机数据  #  唯一数据\n    max-min:\n        数字:最大位数-最小位数\n        字符:字符个数\n        浮点:总位数，小数位数\n\n    u/d/s/f/p:  \n        u:无符号整数\n        d:有符号整数\n        s:字符串\n        f:有符号浮点数\n        p:无符号浮点\n`\n    例如邮件字段格式: \n        'format'=\u003e'#16-4s@%20-1s.%3-2s'\n        唯一的用户名(4-16个字符) @ 域名1-20字符，后缀2-3字符\n\n闭包格式：直接传递一个闭包函数，则数据调用你的闭包函数生成\n\n例如\n```php\n        'format'=\u003efunction($row){  //$row :目前生成的数据集，值传递，不要修改，在字段需要与字段产生关系的时候调用\n                    return mt_rand(time()-30*24*3600,time())  //时间为最近一年某一刻\n                  }\n```\n\n引用数据说明:\u003cbr\u003e\n    格式：[%|#].[表名].[字段名]\u003cbr\u003e   %：可以重复[一对多]，#:不重复[两个表一一对应]，\n    如 from=\"#.member.id' 表示此字段的值来自member表中的id字段，并且是顺序取值\u003cbr\u003e\n\n配置实例\n=\n```php\nreturn [\n    'member'=\u003e[\n        'total'=\u003e10000,\n        'key'=\u003e'id',\n        'define'=\u003e[\n            'avatar'=\u003e['format'=\u003e'http://%8-6s.com/%6s/%10-5s.jpg'],\n            'name'=\u003e['format'=\u003e'%16-4s'],\n        ],\n    ],\n\n    'address'=\u003e[\n        'total'=\u003e5000,\n        'key'=\u003e'id',\n        'define'=\u003e[\n            'userid'=\u003e['format'=\u003e'',from=\u003e'#.member.id'] //数据来自上面member表单字段,member一定要先生成\n            'address'=\u003e['format'=\u003e'%32-16s'],\n            'postcode'=\u003e['format'=\u003efunction($row){\n                $table=[100012,100013,100023,200010];    //随机返回一个数据\n                return $table[mt_rand(0,count($table)-1)];\n            }],\n        ],\n    ],\n];\n```\n\nQQ:79509281\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliryan%2Fdbfiller","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fliryan%2Fdbfiller","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliryan%2Fdbfiller/lists"}