From ee4d88773304f935ac0521569a3e8c5ad82f87e4 Mon Sep 17 00:00:00 2001 From: Xicheng Guo Date: Sat, 26 Oct 2024 14:07:33 +0800 Subject: [PATCH 1/2] update docs --- src/.vitepress/sidebars/sqlite.yaml | 20 +- src/MarkMap.vue | 206 ++++++++++-------- .../sqlite/core-concepts/data-types.md | 27 +++ .../core-concepts/database-operations.md | 22 ++ .../sqlite/introduction/install-sqlite.md | 4 - src/public/images/svg/SQLite.svg | 1 + src/reference.md | 1 + 7 files changed, 180 insertions(+), 101 deletions(-) create mode 100644 src/database/sqlite/core-concepts/data-types.md create mode 100644 src/database/sqlite/core-concepts/database-operations.md create mode 100644 src/public/images/svg/SQLite.svg diff --git a/src/.vitepress/sidebars/sqlite.yaml b/src/.vitepress/sidebars/sqlite.yaml index 4add51c..a851c9d 100644 --- a/src/.vitepress/sidebars/sqlite.yaml +++ b/src/.vitepress/sidebars/sqlite.yaml @@ -4,4 +4,22 @@ - text: 什么是 SQLite link: /database/sqlite/introduction/what-is-sqlite - text: 安装 SQLite - link: /database/sqlite/introduction/install-sqlite \ No newline at end of file + 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#检查数据库 \ No newline at end of file diff --git a/src/MarkMap.vue b/src/MarkMap.vue index 8ee8b02..c78e786 100644 --- a/src/MarkMap.vue +++ b/src/MarkMap.vue @@ -1,123 +1,137 @@ \ No newline at end of file + --> diff --git a/src/database/sqlite/core-concepts/data-types.md b/src/database/sqlite/core-concepts/data-types.md new file mode 100644 index 0000000..73e857f --- /dev/null +++ b/src/database/sqlite/core-concepts/data-types.md @@ -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 开始的秒数 | diff --git a/src/database/sqlite/core-concepts/database-operations.md b/src/database/sqlite/core-concepts/database-operations.md new file mode 100644 index 0000000..d5a8713 --- /dev/null +++ b/src/database/sqlite/core-concepts/database-operations.md @@ -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 +``` diff --git a/src/database/sqlite/introduction/install-sqlite.md b/src/database/sqlite/introduction/install-sqlite.md index b02db94..6c29d9d 100644 --- a/src/database/sqlite/introduction/install-sqlite.md +++ b/src/database/sqlite/introduction/install-sqlite.md @@ -17,7 +17,3 @@ Enter ".help" for usage hints. Connected to a transient in-memory database. Use ".open FILENAME" to reopen on a persistent database. ``` - -继续输入命令 `.open test.db` 可以创建一个数据库文件。 - -输入 `.quit` 退出 SQLite 命令行。 diff --git a/src/public/images/svg/SQLite.svg b/src/public/images/svg/SQLite.svg new file mode 100644 index 0000000..ae7dfdc --- /dev/null +++ b/src/public/images/svg/SQLite.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/reference.md b/src/reference.md index 63380a1..bb61ff4 100644 --- a/src/reference.md +++ b/src/reference.md @@ -8,3 +8,4 @@ - [MDN Web Docs](https://developer.mozilla.org/en-US/) - [Vue.js](https://cn.vuejs.org/) - [Vuex](https://vuex.vuejs.org/zh/) +- [SQLite 教程](https://www.runoob.com/sqlite/sqlite-tutorial.html) From 0df4a9656085539b38fde4dcc27b2208a66e7ce8 Mon Sep 17 00:00:00 2001 From: Xicheng Guo Date: Sat, 26 Oct 2024 15:11:15 +0800 Subject: [PATCH 2/2] update docs --- src/.vitepress/sidebars/sqlite.yaml | 21 +++- .../sqlite/core-concepts/table-operations.md | 104 ++++++++++++++++++ 2 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 src/database/sqlite/core-concepts/table-operations.md diff --git a/src/.vitepress/sidebars/sqlite.yaml b/src/.vitepress/sidebars/sqlite.yaml index a851c9d..0c5687c 100644 --- a/src/.vitepress/sidebars/sqlite.yaml +++ b/src/.vitepress/sidebars/sqlite.yaml @@ -22,4 +22,23 @@ - text: 创建数据库 link: /database/sqlite/core-concepts/database-operations#创建数据库 - text: 检查数据库 - link: /database/sqlite/core-concepts/database-operations#检查数据库 \ No newline at end of file + 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#删除表 + \ No newline at end of file diff --git a/src/database/sqlite/core-concepts/table-operations.md b/src/database/sqlite/core-concepts/table-operations.md new file mode 100644 index 0000000..70c258b --- /dev/null +++ b/src/database/sqlite/core-concepts/table-operations.md @@ -0,0 +1,104 @@ +# 数据表操作 + +## 创建表 + +::: code-group + +```sql [语法] +create table database_name.table_name ( + column1 datatype primary key(one or more columns), + column2 datatype, + ... + columnN datatype +) +``` + +```sql [实例] +create table company ( + id integer primary key not null, + username text not null, + age integer not null, + salary real +) +``` + +::: + +## 查看表 + +使用`.tables`命令查看数据库中的所有表。 + +```bash +sqlite> .tables +company users +``` + +使用`.schema`命令查看表的结构。 + +```bash +sqlite> .schema company +CREATE TABLE company ( + id integer primary key not null, + username text not null, + age integer not null, + salary real +); +``` + +## 修改表 + +### 添加列 + +::: code-group + +```sql [语法] +alter table database_name.table_name add column_name datatype; +``` + +```sql [实例] +alter table company add email text +``` + +::: + +### 重命名列 + +::: code-group + +```sql [语法] +alter table database_name.table_name rename column_name to new_column_name; +``` + +```sql [实例] +alter table company rename username to name; +``` + +::: + +### 删除列 + +::: code-group + +```sql [语法] +alter table database_name.table_name drop column column_name; +``` + +```sql [实例] +alter table company drop column email; +``` + +::: + +## 删除表 + +::: code-group + +```sql [语法] +drop table database_name.table_name +``` + +```sql [实例] +drop table company; +``` + +:::