Blitz comes with a sweet console. The console can be really handy when working on you app. It gives you the ability to interact with the database and run some parts of your application in a shell.
Here are some key commands you can run with the console. These are the same as we'll later use in code:
await db.user.findMany()
// Finds many recordsawait db.user.findFirst()
, ieawait db.user.findFirst({ where: {id: 1} })
// Finds one recordawait db.user.deleteMany()
// Deletes all usersawait db.user.delete()
, ieawait db.user.delete({ where: {id: 1} })
await db.user.create()
, ieawait db.user.create({ data: {email: "someemail@gmail.com", password: "asdasdsa", name: "Test"} })
await db.user.update()
, ieawait db.user.update({ where: {id: 1}, data: {name: "new name"} })
The blitz console supports top-level
await
. So you canawait new Promise((res) => res(console.log("worked")))
without wrapping it in async function 🔥
- Run command
await db.user.findMany()
. You should see a list of all the users in the database.
Right now, our application has a problem. When creating a user through the UI and logging in, there is no name to display: We don't have a field for adding the users name. We will fix that later, but for now - let's fix this using the Blitz console.
- Start
blitz console
- Find the id of the user you created by running
await db.user.findFirst({ where: {email: "<YOUREMAIL>"}})
- Grab the id if your user, and run
await db.user.update({where: {id: <YOUID>}, data: {name: "<YOURNAME>"} })
- Go back to the application running on localhost, and see that the name appears in the header (might need to refresh)