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

データベースの節を読みやすく改善 #657

Merged
merged 2 commits into from
Dec 11, 2023
Merged
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
6 changes: 3 additions & 3 deletions docs/3-web-servers/07-database/_samples/forum/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
<html lang="ja">
<head>
<meta charset="utf-8" />
<title>Title</title>
<title>掲示板</title>
</head>
<body>
<ul>
<!-- messages -->
</ul>
<form method="post" action="/send">
<input placeholder="ここに入力してください。" name="message" />
<button>送信</button>
<input placeholder="メッセージ" name="message" />
<button type="submit">送信</button>
</form>
</body>
</html>
16 changes: 6 additions & 10 deletions docs/3-web-servers/07-database/_samples/forum/main.mjs
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
import { readFileSync } from "node:fs";
import express from "express";
import { PrismaClient } from "@prisma/client";
import { readFileSync } from "node:fs";

const app = express();

app.use(express.urlencoded({ extended: true }));

const client = new PrismaClient();

const template = readFileSync("./index.html", "utf-8");
app.get("/", async (request, response) => {
const messages = await (
await client.forum.findMany()
).map((data) => data.message);
const template = readFileSync("./index.html", "utf-8");
const posts = await client.post.findMany();
const html = template.replace(
"<!-- messages -->",
messages.map((message) => `<li>${message}</li>`).join(""),
posts.map((post) => `<li>${post.message}</li>`).join(""),
);
response.send(html);
});

app.post("/send", async (request, response) => {
await client.forum.create({ data: { message: request.body.message } });
response.send("投稿しました。");
await client.post.create({ data: { message: request.body.message } });
response.redirect("/");
});

app.listen(3000);
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ datasource db {
url = env("DATABASE_URL")
}

model Forum {
model Post {
id Int @id @default(autoincrement())
message String
}
Binary file modified docs/3-web-servers/07-database/create-result.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
122 changes: 93 additions & 29 deletions docs/3-web-servers/07-database/database-application-server.drawio.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/3-web-servers/07-database/find-many-result.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/3-web-servers/07-database/forum.mp4
Binary file not shown.
216 changes: 180 additions & 36 deletions docs/3-web-servers/07-database/index.mdx

Large diffs are not rendered by default.

189 changes: 189 additions & 0 deletions docs/3-web-servers/07-database/load-balancing.drawio.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions src/components/Term/definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ export default {
serverClient: {
name: "サーバーとクライアント",
definition:
"サービスを提供する側のコンピューターやソフトウェアをサーバー、提供される側のコンピューターやソフトウェアをクライアントと呼ぶ。例えば Google Chrome などの Web ブラウザは代表的なクライアントソフトウェアである。",
"サービスを提供する側のコンピューターやソフトウェアをサーバー、提供される側のコンピューターやソフトウェアをクライアントと呼ぶ。例えば Google Chrome などの Web ブラウザは、Web における代表的なクライアントソフトウェアである。",
referencePage: "/docs/web-servers/server/",
},
json: {
Expand All @@ -391,8 +391,8 @@ export default {
"複雑なデータ構造を JavaScript オブジェクトに似た形式で文字列として表現するための記法。",
referencePage: "/docs/web-servers/module/",
},
httpRequestResponse: {
name: "リクエストとレスポンス (HTTP)",
requestResponse: {
name: "リクエストとレスポンス",
definition:
"クライアントからサーバーに対しサービスを要求する通信をリクエスト、リクエストに対してサーバーからクライアントに応答として返される通信をレスポンスと呼ぶ。",
referencePage: "/docs/web-servers/server/",
Expand Down
6 changes: 3 additions & 3 deletions src/components/Term/type-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ const typeMap = new Map([
["サーバー", "serverClient"],
["クライアント", "serverClient"],
["JSON", "json"],
["HTTP リクエスト", "httpRequestResponse"],
["リクエスト", "httpRequestResponse"],
["レスポンス", "httpRequestResponse"],
["HTTP リクエスト", "requestResponse"],
["リクエスト", "requestResponse"],
["レスポンス", "requestResponse"],
["クエリ文字列", "queryString"],
["クエリパラメータ", "queryString"],
["リクエストヘッダ", "httpHeaderBody"],
Expand Down