Skip to content

Use

defineEventHandler

  1. Example of a GET request to the user table
ts
export default defineEventHandler(async () => {
  const connect = await changeNameDbConnect()

  const result = connect
    .select()
    .from(changeNameTables.user)

  return {
    statusCode: 200,
    body: result,
  }
})
  1. Example of a POST request to the user 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.

Released under the MIT License.