Use
defineEventHandler
- Example of a
GET
request to theuser
table
ts
export default defineEventHandler(async () => {
const connect = await changeNameDbConnect()
const result = connect
.select()
.from(changeNameTables.user)
return {
statusCode: 200,
body: result,
}
})
- Example of a
POST
request to theuser
table
ts
export default defineEventHandler(async (event) => {
const body = await readBody(event)
const db = await changeNameDbConnect()
const result = db
.insert(changeNameTables.user)
.values({
name: body.name,
email: body.email,
password: body.password,
createdAt: new Date(),
updatedAt: new Date(),
username: body.username,
})
.returning()
return {
statusCode: 200,
body: result,
}
})
changeName
changeName
is the name of your project. Please change it to your project name.