Git 和 MySQL 的「孩子」,一個可使用 Git 操做的數據庫。近期連續在 GitHub 趨勢榜霸榜,新增 4k+ Star。git
Dolt 是一個 SQL 數據庫,咱們可使用 fork、clone、branch、merge、push、pull 等功能,就像在操做一個 git 倉庫同樣;同時,它也像 MySQL 同樣,只要鏈接上 Dolt,咱們就可使用 SQL 語句進行數據的查詢、更新等操做。使用命令行導入 CSV 文件,提交更改,將其推送到遠程或合併團隊成員的更改。github
Git 的全部命令對於 Dolt 來講都是試用的,徹底一致,Dolt 感受就像是 Git 和 MySQL 的孩子同樣。sql
Dolt 有如下命令:shell
$ dolt Valid commands for dolt are init - 建立一個Dolt數據倉庫. status - 查看工做空間狀態. add - 添加修改到暫存區. reset - 移除暫存區的修改. commit - 提交提交到倉庫. sql - 在倉庫中運行某一個sql命令. sql-server - 啓動MySQL兼容服務器. log - 查看提交日誌. diff - 比較表. blame - 查看錶每行最後修改的用戶及版本號e. merge - 合併分支. branch - 建立,查看,編輯或刪除分支. tag - 建立,查看,編輯或刪除標籤. checkout - 切換某個分支或覆蓋表. remote - 管理遠程倉庫. push - 推送到遠程倉庫. pull - 拉取遠程倉庫數據併合並. fetch - 從遠程倉庫更新數據. clone - clone遠程倉庫數據. creds - 身份憑證的管理. login - 登陸遠程Dolt主機. version - 查看Dolt版本. config - Dolt相關配置. ls - 查看工做區中的表. schema - 查看或導入表結構. table - 複製,重命名,刪除或導出表. conflicts - 查看以及解決合併衝突. migrate - 執行存儲庫遷移以更新爲最新格式. read-tables - 將特定提交處的表提取到新的倉庫中 gc - 從倉庫中清除未引用的數據.
項目地址:
https://github.com/dolthub/dolt數據庫
sudo bash -c 'curl -L https://github.com/dolthub/dolt/releases/latest/download/install.sh | bash'
brew install dolt
go install ./cmd/dolt
以存儲州人口數據爲例,簡單介紹 Dolt 使用。api
$ mkdir state-pops $ cd state-pops
$ dolt init Successfully initialized dolt data repository. $ dolt sql -q "create table state_populations ( state varchar(14), population int, primary key (state) )" $ dolt sql -q "show tables" +-------------------+ | tables | +-------------------+ | state_populations | +-------------------+ $ dolt sql -q "insert into state_populations (state, population) values ('Delaware', 59096), ('Maryland', 319728), ('Tennessee', 35691), ('Virginia', 691937), ('Connecticut', 237946), ('Massachusetts', 378787), ('South Carolina', 249073), ('New Hampshire', 141885), ('Vermont', 85425), ('Georgia', 82548), ('Pennsylvania', 434373), ('Kentucky', 73677), ('New York', 340120), ('New Jersey', 184139), ('North Carolina', 393751), ('Maine', 96540), ('Rhode Island', 68825)" Query OK, 17 rows affected
$ dolt sql -q "select * from state_populations where state = 'New York'" +----------+------------+ | state | population | +----------+------------+ | New York | 340120 | +----------+------------+
$ dolt add . $ dolt commit -m "initial data" $ dolt status On branch master nothing to commit, working tree clean
$ dolt sql # Welcome to the DoltSQL shell. # Statements must be terminated with ';'. # "exit" or "quit" (or Ctrl-D) to exit. state_pops> update state_populations set population = 0 where state like 'New%'; Query OK, 3 rows affected Rows matched: 3 Changed: 3 Warnings: 0 state_pops> exit Bye
$ dolt diff diff --dolt a/state_populations b/state_populations --- a/state_populations @ qqr3vd0ea6264oddfk4nmte66cajlhfl +++ b/state_populations @ 17cinjh5jpimilefd57b4ifeetjcbvn2 +-----+---------------+------------+ | | state | population | +-----+---------------+------------+ | < | New Hampshire | 141885 | | > | New Hampshire | 0 | | < | New Jersey | 184139 | | > | New Jersey | 0 | | < | New York | 340120 | | > | New York | 0 | +-----+---------------+------------+
$ dolt add state_populations $ dolt commit -m "More like Old Jersey"
$ head -n3 data.csv state,population Delaware,59096 Maryland,319728 $ dolt table import -c -pk=state state_populations data.csv
$ dolt checkout -b <branch> $ dolt merge <branch>
$ dolt clone dolthub/corona-virus ... $ cd corona-virus $ dolt remote -v origin https://doltremoteapi.dolthub.com/dolthub/corona-virus
$ dolt remote add origin myname/myRepo $ dolt remote -v origin https://doltremoteapi.dolthub.com/myname/myRepo $ dolt push origin master
內容轉載於 「開源前哨」