Programmatically dummifies your database to non-sensitive data for development use!
// 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@dummify.php'); // (Optional)
})
->update(function ($row) {
$row->email = 'email2@dummify.php';
return $row;
})
Thanks to Composer it is quite easy!
$ composer require --dev dummify/dummify.php
And on your code:
include '/vendor/autoload.php';
use Dummify\Dummify;
Using Illuminate\Database
capsule for database connections, Dummify
can connect to:
- MySQL
- PostgreSQL
- SQL Server
- SQLite
To create a new connection you need an array of parameters like this one:
There is an example here!
$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,
];
There is an example here!
$connection = [
'driver' => 'pgsql',
'host' => '127.0.0.1',
'port' => '5432',
'database' => 'example',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
'sslmode' => 'prefer',
];
There is an example here!
$connection = [
'driver' => 'sqlsrv',
'host' => '127.0.0.1'),
'port' => '1433',
'database' => 'example',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'prefix' => '',
];
There is an example here!
$connection = [
'driver' => 'sqlite',
'database' => '/static/path/to/database.sqlite',
'prefix' => '',
];
Or you can use in memory connection like this:
$connection = [
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => '',
];
Once you have your connection array you can connect into your database using:
$dummify = Dummify::connectTo($connection)
Later you may choose a table using the from($table)
method.
$dummify->from('users')
You may populate a table using the insert(callable $callable, $iterations = 1)
method. In this case we are using
Faker to help us generate random data!
$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);
You may setup how the iterator will work over each line using the update(callable $callable)
method!
$faker = Faker\Factory::create();
$dummify
->from('users')
->update(function($row){
$row->name = $faker->name
$row->email = $faker->email
return $row
});
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;
$dummify->from('users', function($query) {
return $query->where('name', 'like', '%Filipe%');
});