Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dummify/dummify.php
Programmatically dummifies your database to non-sensitive data for development use!
https://github.com/dummify/dummify.php
database dummy dummy-data fake-data faker mysql php sensitive-data sql-server
Last synced: about 2 months ago
JSON representation
Programmatically dummifies your database to non-sensitive data for development use!
- Host: GitHub
- URL: https://github.com/dummify/dummify.php
- Owner: dummify
- License: mit
- Created: 2017-11-16T20:08:50.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2017-12-09T19:32:23.000Z (about 7 years ago)
- Last Synced: 2024-10-12T07:41:13.982Z (3 months ago)
- Topics: database, dummy, dummy-data, fake-data, faker, mysql, php, sensitive-data, sql-server
- Language: PHP
- Homepage:
- Size: 133 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
## Dummify.php
> Programmatically dummifies your database to non-sensitive data for development use!
[![Build Status](https://travis-ci.org/dummify/dummify.php.svg?branch=master)](https://travis-ci.org/dummify/dummify.php) [![StyleCI](https://styleci.io/repos/111016957/shield?branch=master)](https://styleci.io/repos/111016957) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/dummify/dummify.php/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/dummify/dummify.php/?branch=master)
### TL;DR
```php
// Use an array of parameters to connect to a database
$connection = ['driver' => 'sqlite', 'database' => ':memory:'];// You may populate your database with dummy data
$faker = Faker\Factory::create();Dummify::connectTo($connection)
->from('users')
->insert(function($row) {
$row->name = $faker->name;
$row->email = $faker->email;
return $row;
});// Or you can dummify with a new rule
Dummify::connectTo($connection)
->from('users', function ($query) {
return $query->where('email', '[email protected]'); // (Optional)
})
->update(function ($row) {
$row->email = '[email protected]';
return $row;
})
```### Install Dummify
Thanks to [Composer](https://getcomposer.org/) it is quite easy!
```bash
$ composer require --dev dummify/dummify.php
```And on your code:
```php
include '/vendor/autoload.php';use Dummify\Dummify;
```### Setup a connection
Using [`Illuminate\Database`](https://github.com/illuminate/database) capsule for database connections, `Dummify` can connect to:
- MySQL
- PostgreSQL
- SQL Server
- SQLiteTo create a new connection you need an array of parameters like this one:
##### MySQL/MariaDB connection
There is an [example here](https://github.com/laravel/laravel/blob/master/config/database.php#L42)!
```php
$connection = [
'driver' => 'mysql',
'host' => '127.0.0.1',
'port' => '3306',
'database' => 'example',
'username' => 'root',
'password' => '',
'unix_socket' => '',
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
];
```##### PostgreSQL connection
There is an [example here](https://github.com/laravel/laravel/blob/master/config/database.php#L57)!
```php
$connection = [
'driver' => 'pgsql',
'host' => '127.0.0.1',
'port' => '5432',
'database' => 'example',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
'sslmode' => 'prefer',
];
```##### SQL Server connection
There is an [example here](https://github.com/laravel/laravel/blob/master/config/database.php#L70)!
```php
$connection = [
'driver' => 'sqlsrv',
'host' => '127.0.0.1'),
'port' => '1433',
'database' => 'example',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'prefix' => '',
];
```##### SQLite connection
There is an [example here](https://github.com/laravel/laravel/blob/master/config/database.php#L36)!
```php
$connection = [
'driver' => 'sqlite',
'database' => '/static/path/to/database.sqlite',
'prefix' => '',
];
```Or you can use in memory connection like this:
```php
$connection = [
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => '',
];
```### Instantiate a Dummify
Once you have your connection array you can connect into your database using:
```php
$dummify = Dummify::connectTo($connection)
```Later you may choose a table using the `from($table)` method.
```php
$dummify->from('users')
```### Populate a table with dummy data
You may populate a table using the `insert(callable $callable, $iterations = 1)` method. In this case we are using
[Faker](https://github.com/fzaninotto/Faker) to help us generate random data!```php
$faker = Faker\Factory::create();$dummify
->from('users')
->insert(function($row){
$row->name = $faker->name
$row->email = $faker->email
return $row;
});// (Optional) You can pass how many you want to create
$dummify
->from('users')
->insert(function($row){
$row->name = $faker->name
$row->email = $faker->email
return $row;
}, 100);
```### Update a table with dummy data
You may setup how the iterator will work over each line using the `update(callable $callable)` method!
```php
$faker = Faker\Factory::create();$dummify
->from('users')
->update(function($row){
$row->name = $faker->name
$row->email = $faker->email
return $row
});
```#### Making restrictions for updates
If you are interested on limiting or adding conditions to your SQL query, you can use all `Illuminate\Database` fluent syntax!For more docs about it follow-up with `Laravel` [docs](https://laravel.com/docs/queries);
```php
$dummify->from('users', function($query) {
return $query->where('name', 'like', '%Filipe%');
});
```