DEV Community

Cover image for Playing with ChatGPT to generate dummy/fake data.
Buddhi Eashwarage
Buddhi Eashwarage

Posted on

7

Playing with ChatGPT to generate dummy/fake data.

If you're a software engineer, you know how important dummy data!!

When you need to test some piece of software locally which interacts with data, it's crucial to have a set of dummy data created.

One way to do that is generating the dummy data manually which is the old school way.

But nowadays we can use a free open source library to accomplish this task.

People who have exposed to PHP, well aware with FakerPHP library. And if you are using some framework like Laravel, it has a seperate Seeder class which allows to seed the database tables with dummy data.

Image description
Therefore, we can call FakerPHP helper methods to generate dummy or fake data for us.

But with all these libraries we can't see the generated data until the process is completed since it's a direct interaction with the database behind the scene.

I think we can use ChatGPT to overcome from this issue. While some people bothering whether ChatGPT will take over all the software engineering jobs, we can find smarter ways to use it to improve the efficiency as software engineers.

Image description
Let's jump into ChatGPT and let's start with a dummy data table prior exploring the database seeders.

Simply I started with the following command.

My intention is to create a dummy product data table with the given parameters when creating a product.
Image description

What will be the ChatGPT's reply?

This is the reply.

Image description

It not only created a table filled with dummy data, but also provided a brief explanation too. How awesome right?

Then my idea was to convert those dummy data into JSON format which permits me later to copy and paste during my data populating process.

So I asked the following question.
Image description

It was smart enough to provide me the generated data in JSON format.
Image description

This is the complete output.
[
{
"name": "Widget A",
"sku": "WIDG001",
"quantity": 10,
"price": 29.99
},
{
"name": "Widget B",
"sku": "WIDG002",
"quantity": 5,
"price": 14.99
},
{
"name": "Widget C",
"sku": "WIDG003",
"quantity": 20,
"price": 9.99
},
{
"name": "Thingamajig X",
"sku": "THING001",
"quantity": 15,
"price": 49.99
},
{
"name": "Thingamajig Y",
"sku": "THING002",
"quantity": 7,
"price": 99.99
},
{
"name": "Thingamajig Z",
"sku": "THING003",
"quantity": 3,
"price": 199.99
}
]

End of the response it had provided a brief explanation again as below.

Image description

Do you think I stopped from there? NO!!

I wanted to check whether it can provide a specific PHP framework oriented solution.

So I asked the following question.
Image description

It started to guide me with a step by step approach which was really cool.

Image description

Image description

Complete code.

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;

class ProductsTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $products = [
            [
                'name' => 'Widget A',
                'sku' => 'WIDG001',
                'quantity' => 10,
                'price' => 29.99
            ],
            [
                'name' => 'Widget B',
                'sku' => 'WIDG002',
                'quantity' => 5,
                'price' => 14.99
            ],
            [
                'name' => 'Widget C',
                'sku' => 'WIDG003',
                'quantity' => 20,
                'price' => 9.99
            ],
            [
                'name' => 'Thingamajig X',
                'sku' => 'THING001',
                'quantity' => 15,
                'price' => 49.99
            ],
            [
                'name' => 'Thingamajig Y',
                'sku' => 'THING002',
                'quantity' => 7,
                'price' => 99.99
            ],
            [
                'name' => 'Thingamajig Z',
                'sku' => 'THING003',
                'quantity' => 3,
                'price' => 199.99
            ]
        ];

        DB::table('products')->insert($products);
    }
}

Enter fullscreen mode Exit fullscreen mode

End of the code as usual it was giving a brief explanation as well.

Image description

Image description

Happy coding!!

Sentry blog image

How to reduce TTFB

In the past few years in the web dev world, we’ve seen a significant push towards rendering our websites on the server. Doing so is better for SEO and performs better on low-powered devices, but one thing we had to sacrifice is TTFB.

In this article, we’ll see how we can identify what makes our TTFB high so we can fix it.

Read more

Top comments (0)

Cloudinary image

Video API: manage, encode, and optimize for any device, channel or network condition. Deliver branded video experiences in minutes and get deep engagement insights.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay