diff --git a/javascript/sveltekit/src/routes/api/todos/+page.server.js b/javascript/sveltekit/src/routes/api/todos/+page.server.js index 7da2488..bcf9ddd 100644 --- a/javascript/sveltekit/src/routes/api/todos/+page.server.js +++ b/javascript/sveltekit/src/routes/api/todos/+page.server.js @@ -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, + }; }