Skip to content

Commit

Permalink
Merge pull request #118 from GuoXiCheng/dev-c
Browse files Browse the repository at this point in the history
update docs
  • Loading branch information
GuoXiCheng authored Oct 26, 2024
2 parents ebcb6ab + 0df4a96 commit 71e68b6
Show file tree
Hide file tree
Showing 8 changed files with 303 additions and 101 deletions.
39 changes: 38 additions & 1 deletion src/.vitepress/sidebars/sqlite.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,41 @@
- text: 什么是 SQLite
link: /database/sqlite/introduction/what-is-sqlite
- text: 安装 SQLite
link: /database/sqlite/introduction/install-sqlite
link: /database/sqlite/introduction/install-sqlite
- text: 核心概念
items:
- text: 数据类型
link: /database/sqlite/core-concepts/data-types
items:
- text: 存储类
link: /database/sqlite/core-concepts/data-types#存储类
- text: Boolean 数据类型
link: /database/sqlite/core-concepts/data-types#boolean-数据类型
- text: 日期和时间数据类型
link: /database/sqlite/core-concepts/data-types#日期和时间数据类型
- text: 数据库操作
link: /database/sqlite/core-concepts/database-operations
items:
- text: 创建数据库
link: /database/sqlite/core-concepts/database-operations#创建数据库
- text: 检查数据库
link: /database/sqlite/core-concepts/database-operations#检查数据库
- text: 数据表操作
link: /database/sqlite/core-concepts/table-operations
items:
- text: 创建表
link: /database/sqlite/core-concepts/table-operations#创建表
- text: 查看表
link: /database/sqlite/core-concepts/table-operations#查看表
- text: 修改表
link: /database/sqlite/core-concepts/table-operations#修改表
items:
- text: 添加列
link: /database/sqlite/core-concepts/table-operations#添加列
- text: 重命名列
link: /database/sqlite/core-concepts/table-operations#重命名列
- text: 删除列
link: /database/sqlite/core-concepts/table-operations#删除列
- text: 删除表
link: /database/sqlite/core-concepts/table-operations#删除表

206 changes: 110 additions & 96 deletions src/MarkMap.vue
Original file line number Diff line number Diff line change
@@ -1,123 +1,137 @@
<template>
<div id="container">
<svg id="markmap" style="width: 100%; height: 90vh"></svg>
</div>
<div id="container">
<svg id="markmap" style="width: 100%; height: 90vh"></svg>
</div>
</template>

<script setup lang="ts">
import { onMounted } from 'vue';
import { Transformer } from 'markmap-lib';
import { Markmap, loadCSS, loadJS } from 'markmap-view';
import { Toolbar } from 'markmap-toolbar';
import { onMounted } from "vue";
import { Transformer } from "markmap-lib";
import { Markmap, loadCSS, loadJS } from "markmap-view";
import { Toolbar } from "markmap-toolbar";
let markmapInstance: Markmap | null = null;
const props = defineProps({
markdown: String
})
markdown: String,
});
onMounted(() => {
const markmapFormat = convertMarkdown(props.markdown);
localStorage.setItem('markmap-state-raw', JSON.stringify(markmapFormat));
createOrUpdateMarkmap(markmapFormat);
addToolbar(markmapInstance);
const markmapFormat = convertMarkdown(props.markdown);
localStorage.setItem("markmap-state-raw", JSON.stringify(markmapFormat));
createOrUpdateMarkmap(markmapFormat);
addToolbar(markmapInstance);
});
const createOrUpdateMarkmap = (markmapFormat) => {
if (markmapInstance) {
markmapInstance.destroy();
}
markmapInstance = Markmap.create('#markmap', undefined, markmapFormat);
// 滚动到当前节点
document.querySelectorAll(".markmap-node").forEach((node) => {
node.addEventListener('click', (event) => {
setTimeout(() => {
const activeNode = document.querySelector('.is-active');
if (activeNode) {
activeNode.scrollIntoView({ behavior: 'auto', block: 'center' });
}
}, 600)
});
if (markmapInstance) {
markmapInstance.destroy();
}
markmapInstance = Markmap.create("#markmap", undefined, markmapFormat);
// 滚动到当前节点
document.querySelectorAll(".markmap-node").forEach((node) => {
node.addEventListener("click", (event) => {
setTimeout(() => {
const activeNode = document.querySelector(".is-active");
if (activeNode) {
activeNode.scrollIntoView({ behavior: "auto", block: "center" });
}
}, 600);
});
}
});
};
const convertMarkdown = (markdown) => {
const transformer = new Transformer();
const { root, features } = transformer.transform(markdown);
const transformer = new Transformer();
const { root, features } = transformer.transform(markdown);
const assets = transformer.getAssets();
const assets = transformer.getAssets();
if (assets.styles) loadCSS(assets.styles);
if (assets.scripts) loadJS(assets.scripts, { getMarkmap: () => (window as any).markmap });
if (assets.styles) loadCSS(assets.styles);
if (assets.scripts) loadJS(assets.scripts, { getMarkmap: () => (window as any).markmap });
return root;
}
return root;
};
const addToolbar = (markmap) => {
Toolbar.defaultItems = [{
content: createElementImg('Docker'),
title: 'Docker',
onClick: () => {
const markmapRaw = localStorage.getItem('markmap-state-raw') as string;
createOrUpdateMarkmap(JSON.parse(markmapRaw).children[3].children[0]);
}
}, {
content: createElementImg('React'),
title: 'React',
onClick: () => {
const markmapRaw = localStorage.getItem('markmap-state-raw') as string;
createOrUpdateMarkmap(JSON.parse(markmapRaw).children[1].children[1]);
}
}, {
content: createElementImg('NodeJS'),
title: 'NodeJS',
onClick: () => {
const markmapRaw = localStorage.getItem('markmap-state-raw') as string;
createOrUpdateMarkmap(JSON.parse(markmapRaw).children[2].children[0]);
}
}, {
content: createElementImg('JavaScript'),
title: 'JavaScript',
onClick: () => {
const markmapRaw = localStorage.getItem('markmap-state-raw') as string;
createOrUpdateMarkmap(JSON.parse(markmapRaw).children[0]);
}
}, {
content: createElementImg('Vue'),
title: 'Vue',
onClick: () => {
const markmapRaw = localStorage.getItem('markmap-state-raw') as string;
createOrUpdateMarkmap(JSON.parse(markmapRaw).children[1].children[0]);
}
}, {
content: createElementImg('All'),
title: 'All',
onClick: () => {
const markmapRaw = localStorage.getItem('markmap-state-raw') as string;
createOrUpdateMarkmap(JSON.parse(markmapRaw));
}
}];
Toolbar.defaultItems = [
{
content: createElementImg("SQLite"),
title: "SQLite",
onClick: () => {
const markmapRaw = localStorage.getItem("markmap-state-raw") as string;
createOrUpdateMarkmap(JSON.parse(markmapRaw).children[3].children[0]);
},
},
{
content: createElementImg("Docker"),
title: "Docker",
onClick: () => {
const markmapRaw = localStorage.getItem("markmap-state-raw") as string;
createOrUpdateMarkmap(JSON.parse(markmapRaw).children[4].children[0]);
},
},
{
content: createElementImg("React"),
title: "React",
onClick: () => {
const markmapRaw = localStorage.getItem("markmap-state-raw") as string;
createOrUpdateMarkmap(JSON.parse(markmapRaw).children[1].children[1]);
},
},
{
content: createElementImg("NodeJS"),
title: "NodeJS",
onClick: () => {
const markmapRaw = localStorage.getItem("markmap-state-raw") as string;
createOrUpdateMarkmap(JSON.parse(markmapRaw).children[2].children[0]);
},
},
{
content: createElementImg("JavaScript"),
title: "JavaScript",
onClick: () => {
const markmapRaw = localStorage.getItem("markmap-state-raw") as string;
createOrUpdateMarkmap(JSON.parse(markmapRaw).children[0]);
},
},
{
content: createElementImg("Vue"),
title: "Vue",
onClick: () => {
const markmapRaw = localStorage.getItem("markmap-state-raw") as string;
createOrUpdateMarkmap(JSON.parse(markmapRaw).children[1].children[0]);
},
},
{
content: createElementImg("All"),
title: "All",
onClick: () => {
const markmapRaw = localStorage.getItem("markmap-state-raw") as string;
createOrUpdateMarkmap(JSON.parse(markmapRaw));
},
},
];
const toolbar = Toolbar.create(markmap);
toolbar.setBrand(false)
const toolbar = Toolbar.create(markmap);
toolbar.setBrand(false);
toolbar.el.style.position = 'absolute';
toolbar.el.style.bottom = '0.5rem';
toolbar.el.style.right = '0.5rem';
document.getElementById('container')?.appendChild(toolbar.el);
}
toolbar.el.style.position = "absolute";
toolbar.el.style.bottom = "0.5rem";
toolbar.el.style.right = "0.5rem";
document.getElementById("container")?.appendChild(toolbar.el);
};
const createElementImg = (filename) => {
const img = document.createElement('img');
img.src = `/images/svg/${filename}.svg`;
img.style.width = '1.5rem';
img.style.height = '1.5rem';
img.style.cursor = 'pointer';
return img;
}
const img = document.createElement("img");
img.src = `/images/svg/${filename}.svg`;
img.style.width = "1.5rem";
img.style.height = "1.5rem";
img.style.cursor = "pointer";
return img;
};
</script>

<!-- <script>
Expand Down Expand Up @@ -216,4 +230,4 @@ export default {
}
}
};
</script> -->
</script> -->
27 changes: 27 additions & 0 deletions src/database/sqlite/core-concepts/data-types.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 数据类型

## 存储类

每个存储在 SQLite 数据库中的值都具有以下存储类之一:

| 存储类 | 描述 |
| ------- | ------------------ |
| NULL | 值是一个 NULL 值 |
| INTEGER | 值是一个有符号整数 |
| REAL | 值是一个浮点数 |
| TEXT | 值是一个文本字符串 |
| BLOB | 值是一个 blob 数据 |

## Boolean 数据类型

SQLite 没有单独的 Boolean 存储类,布尔值被存储为整数 0(false)和 1(true)。

## 日期和时间数据类型

SQLite 没有单独的用于存储日期或时间的存储类,日期和时间被存储为 TEXT、REAL 或 INTEGER。

| 存储类 | 日期格式 |
| ------- | -------------------------------------------------- |
| TEXT | "YYYY-MM-DD HH:MM:SS.SSS" |
| REAL | 从公元前 4714 年 11 月 24 日格林尼治时间开始的天数 |
| INTEGER | 从 1970-01-01 00:00:00 UTC 开始的秒数 |
22 changes: 22 additions & 0 deletions src/database/sqlite/core-concepts/database-operations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# 数据库操作

在命令行中输入`sqlite3`命令,进入 sqlite3 的命令行模式。

在命令行中输入`.quit`命令,退出 sqlite3 的命令行模式。

## 创建数据库

使用 `.open` 命令创建一个数据库文件,如果文件不存在则会创建一个新的数据库文件,如果文件已经存在则会打开该数据库文件。

```bash
sqlite> .open test.db
```

## 检查数据库

使用 `.databases` 命令查看当前打开的数据库文件。

```bash
sqlite> .databases
main: C:\sqlite\test.db r/w
```
Loading

0 comments on commit 71e68b6

Please sign in to comment.