-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
04b30dc
commit e2da604
Showing
1 changed file
with
23 additions
and
23 deletions.
There are no files selected for viewing
46 changes: 23 additions & 23 deletions
46
javascript/sveltekit/src/routes/api/todos/+page.server.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,29 @@ | ||
import { oceanbaseConnection } from '../../../lib/db/oceanbase'; | ||
import { createOceanbaseConnection } from '../../../lib/db/oceanbase'; | ||
|
||
export async function get() { | ||
let results = await oceanbaseConnection | ||
.query('SELECT * FROM tasks') | ||
.then(function ([rows, fields]) { | ||
console.log(rows); | ||
return rows; | ||
}); | ||
let results = await createOceanbaseConnection() | ||
.query('SELECT * FROM tasks') | ||
.then(function ([rows, fields]) { | ||
console.log(rows); | ||
return rows; | ||
}); | ||
|
||
return { | ||
body: results, | ||
}; | ||
return { | ||
body: results, | ||
}; | ||
} | ||
export async function post(request) { | ||
console.log(request); | ||
const { text, completed } = request.body; | ||
let newTask = await oceanbaseConnection | ||
.query('INSERT INTO tasks (text, completed) VALUES (?, ?)', [ | ||
text, | ||
completed, | ||
]) | ||
.then(function ([result]) { | ||
return { id: result.insertId, text: text, completed: completed }; | ||
}); | ||
return { | ||
body: newTask, | ||
}; | ||
console.log(request); | ||
const { text, completed } = request.body; | ||
let newTask = await createOceanbaseConnection() | ||
.query('INSERT INTO tasks (text, completed) VALUES (?, ?)', [ | ||
text, | ||
completed, | ||
]) | ||
.then(function ([result]) { | ||
return { id: result.insertId, text: text, completed: completed }; | ||
}); | ||
return { | ||
body: newTask, | ||
}; | ||
} |