Posts

Showing posts from October, 2024

PostgreSQL 具有的 NoSQL 特性

Image
了解了 RDBMS 與 NoSQL 的差異之後,我們來了解 PostgreSQL 除了本是 RDBMS 之外,還包含了哪些 NoSQL 的特性: PS: 可依下列步驟先在地端用 docker 啟一個 postgreSQL database 1. pull posgres image and run docker run -d \ --name postgres-db \ -e POSTGRES_USER=postgres \ -e POSTGRES_PASSWORD=password \ -e POSTGRES_DB=postgres \ -p 5432:5432 \ postgres 2. 建立一個 demo database psql -h localhost -p 5432 -U postgres -c "CREATE DATABASE nosql_demo;" 3. 連線 psql -h localhost -p 5432 -U postgres -W -d nosql_demo 4. 輸入密碼 password Password: Document types 1. XML documents 是一種 Hierarchical structured 1. 用 xml text 建立資料 Examples: // create xmltest table CREATE TABLE xmltest ( data xml NOT NULL ); // 插入一筆 xmltest 資料 INSERT INTO xmltest (data) VALUES ( '<attendee><bio> <name>John Doe</name> <birthYear> 1986 </birthYear></bio><languages> <lang level = "5" >php</lang><lang level = "4" >python</lang> <lang level = "2" ...

RDBMS 與 NoSQL 的比較

Image
RDBMS vs NoSQL 了解 RDBMS 與 SQL 的關係 《RDBMS 與 SQL 的差異,他們是一樣的嗎?》 之後,讓我們來看看什麼是 NoSQL,並比較 Relation database 與 NoSQL database 的差異。 首先, 我們來看看什麼是 Relational Model。 Relational Model & Relational Database RDBMS 多用關聯式模型 Relational Model 作為儲存資料的結構。 儲存資料的模型 data model 有很多種,像是最早的網狀模型 network model 和層次模型 hierarchical model,以及現在也廣為使用的文件模型 document model。 而目前在 RDBMS 中最廣為人知的資料模型,非 關聯式模型 relational model 莫屬。 資料彼此間用關係連結,在 SQL 中稱 tables ,每個關聯是複數個 tuples 的非排序集合,在 SQL 中稱 rows。 data is organized into relations (called tables in SQL), where each relation is an unordered collection of tuples ( rows in SQL). NoSQL Database 只有簡單一句 Not Only SQL 所以基本上,只要不是 SQL 的都屬於這一類! SQL 與 NoSQL 有各自擅長的部分 SQL 關聯式模型可以提供很好的 joins 支援,以及表單中很好的的  many-to-one 和 many-to-many 關聯。 The relational model counters by providing better support for joins, and many-to-one and many-to-many relationships. NoSQL 而 NoSQL 中常用的文件模型,則是讓 schema 更具彈性,因為 locality 特性所以有較好的效能,而且在某些應用程式中,具有更貼近應用程式資料的結構(相比之下 SQL 就有 impedance mismatch 的問題,所以才會衍生出 ORM)。 T...

RDBMS 與 SQL 的差異,他們是一樣的嗎?

Image
RDBMS vs SQL 會想寫這一篇是因為我每次都說 SQL, NoSQL,當有一天有人問我 RDBMS 與 NoSQL 資料庫差異時,我想說:「不就 SQL 跟 NoSQL 的差異嗎?」 但其實 RDBMS ≠ SQL 唷! RDBMS 與 SQL 的區別 — 記住,一個是 關連式資料庫 管理系統 ,一個是 關連式資料庫中常用來 查詢資料的 高階語言 ! RDBMS 其實看名字就知道,RDBMS 全名是 Relational Database Management System。他是資料庫軟體,可以做資料的管理、儲存、查詢、更新等。其資料儲存使用的是關聯式模型。資料儲存的模型有很多種,有興趣的可以參考 RDBMS vs NoSQL 。 An RDBMS is a Relational Database Management System. It is the database software itself, which manages storage, querying, updating, and, well, everything. Specifically, an RDBMS uses a relational model of data, as the name suggests. SQL SQL 的全名是 Structured Query Language,顧名思義是種高階語言,而且是 declarative 類別,常用在 RDBMS 中的查詢語言。不曉得 declarative 是什麼意思的朋,可以參考下方的補充。 SQL, the Structured Query Language, is a declarative query language which is typically used to query the RDBMS. 結論 SQL 是常用來與 RDBMS 系統互動的語言。也就是說你,可以用其他語言跟 RDBMS 互動,也可以用 SQL 跟其他資料庫系統互動。 So: the RDBMS is the system, and SQL is the language used to interact with the system. In principle you could have an RDBMS that uses s...

程式語言初學者 Docker 入門第九章 —— Docker Compose

Orchestration: 執行多個 Docker Container 的快速協作編排 定義和運行多個 Docker 容器的應用程式 藉由一個 docker-compose.yml (YAML 格式) 檔來定義一組相互關聯的應用系統容器,成為一個獨立專案 兩部份重要觀念: Service: 一套應用系統容器,實際上可以包括若干個運行相同 image 的 container project: 由一組相關聯的應用系統容器組成的一個完整業務單元 咱們直接來進入實作,從底下 Github repo 照著 README.md 步驟即可以 run 起兩個 container,透過網路互相連接 docker-compose demo

程式語言初學者 Docker 入門第八章 —— 使用 Dockerfile 建立映像檔

 Dockerfile 是一個文字格式的設定檔,使用者可以使用 Dockerfile 快速建立自訂的映像檔 1. 基本結構 以行為單位的命語句所組成,並且支援以 # 開頭標示為註解行。 由 4 部分組成 基礎印象檔資訊 第一行必需指定基於的基礎映像檔,若欲建立基礎映像檔則可使用 scratch 空白印象檔 FROM ubuntu 維護者資訊 docker_user <docker_user at email.com > (@docker_user) MAINTAINER docker_user docker_user@email.com 映像檔操作指令 RUN echo "deb http://archive.ubuntu.com/ubuntu/ raring main universe" >> /etc/apt/sources.list RUN apt-get update && apt-get install -y nginx RUN echo "\ndaemon off;" >> /etc/nginx/nginx.conf 容器啟動時需執行指令 CMD /usr/sbni/nginx # This dockerfile uses the ubuntu image # Version 2 - EDITION 1 # Author: docker_user # Command format: Instruction [arguments / command] .. 2. 指令說明 1. FROM 所有 Dockerfile 中的第一道指令 建立多個映像檔,可以使用多個 FROM FROM <image> FROM <image>:<tag> FROM <image>@<digest> 2. MAINTAINER MAINTAINER <name> MAINTAINER image_creator@docker.com 該資訊會寫入產程映像檔的 Author 名稱屬性中 3. RUN 運行指定命令 格式為 RUN <com...