winglang / wing

A programming language for the cloud ☁️ A unified programming model, combining infrastructure and runtime code into one language ⚡
https://winglang.io
Other
5.05k stars 198 forks source link

Add ability to seed database in the Wing console #7128

Open boyney123 opened 2 months ago

boyney123 commented 2 months ago

Use Case

I'm building an application at the moment, Vite on the frontend and building an API using Wing that connects to DynamoDB.

Every time I make a change my data is deleted from my table (which is already raised here https://github.com/winglang/wing/issues/7107).

It would be nice as a developer to seed my table in development with information, maybe I can do this in the console? Not sure I would want to seed with Wing code itself? Not sure.... although I can think of practical usecases for this, but I think if I was seeding in production I would write code that handles this for me on the init of my custom class for example.....

But in this usecase I'm in development mode, and I just want some data to play with in the UI, I would love Wing to support that. the ability to bootstrap my database with information.

Proposed Solution

Add new tool in the console to allow me to seed tables in the table component, and persist this information between refreshes and restarts of the wing console (when I make changes to FE and BE code).

Implementation Notes

No response

Component

No response

Community Notes

Chriscbr commented 2 months ago

@boyney123 One way you can seed resources in Wing code today is by specifying a piece of inflight code that should run when your app is deployed, using cloud.OnDeploy: https://www.winglang.io/docs/api/standard-library/cloud/on-deploy. When your app is running on the simulator, it'll be executed each time the app is reloaded.

For example, you can add an inflight that says "if the table is empty, insert these N items"

Having a way to insert or upload information through the Console sounds like it would be handy as well though, especially once we have https://github.com/winglang/wing/issues/7107 fixed