Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: patch js #43

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
13 changes: 13 additions & 0 deletions applications/js/sveltekit/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## how to dev

prerequirement

- nodejs
- oceanbase 单机版

git clone xxx
npm install
npm run dev

npm run build
node .svelte-kit/output/server/index.js
File renamed without changes.
12 changes: 12 additions & 0 deletions applications/js/sveltekit/src/app.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
%sveltekit.head%
</head>
<body data-sveltekit-preload-data="hover">
<div style="display: contents">%sveltekit.body%</div>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createOceanbaseConnection } from '../../../lib/db';
import { createOceanbaseConnection } from '../../../vendor/db';

export async function post() {
let results = await createOceanbaseConnection()
Expand Down
49 changes: 49 additions & 0 deletions applications/js/sveltekit/src/routes/api/todos/[id].js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { createOceanbaseConnection } from '../../../vendor/db';

export async function del(req) {
const { id } = req.params;

try {
await createOceanbaseConnection().query('DELETE FROM tasks WHERE id = ?', [
id,
]);
return {
status: 200,
body: { message: `Todo with id ${id} deleted successfully.` },
};
} catch (error) {
console.error('Error deleting todo:', error);
return {
status: 500,
body: { message: 'Error deleting todo. Please try again later.' },
};
}
}
export async function put(req) {
const { id } = req.params;
const { completed } = req.body;

try {
await createOceanbaseConnection().query(
'UPDATE tasks SET completed = ? WHERE id = ?',
[completed, id],
);
const [updatedTodo] = await createOceanbaseConnection().query(
'SELECT * FROM tasks WHERE id = ?',
[id],
);
return {
status: 200,
body: JSON.stringify(updatedTodo),
};
} catch (error) {
console.error('Error toggling todo completed status:', error);
return {
status: 500,
body: {
message:
'Error toggling todo completed status. Please try again later.',
},
};
}
}
18 changes: 18 additions & 0 deletions applications/js/sveltekit/src/vendor/db.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export function createOceanbaseConnection() {
return new Promise((resolve, reject) => {
const mysql = require('mysql2');
const connection = mysql.createConnection({
host: '127.0.0.',
user: 'root@test',
port: '2881',
password: '',
database: 'test',
});
connection.connect((err) => {
if (err) {
reject(err);
}
resolve(connection);
});
});
}
13 changes: 13 additions & 0 deletions applications/js/sveltekit/svelte.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import adapter from '@sveltejs/adapter-auto';

/** @type {import('@sveltejs/kit').Config} */
const config = {
kit: {
// adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list.
// If your environment is not supported, or you settled on a specific environment, switch out the adapter.
// See https://kit.svelte.dev/docs/adapters for more information about adapters.
adapter: adapter(),
},
};

export default config;
34 changes: 0 additions & 34 deletions javascript/sveltekit/README.md

This file was deleted.

Loading