[introduction]: the “child” of GIT and MYSQL, a database that can be operated using GIT. Recently, it has dominated the GitHub trend list for three consecutive days, adding 4K + star.
Dolt is an SQL database. We can use fork, clone, branch, merge, push, pull and other functions, just like operating a git warehouse; At the same time, like mysql, as long as dolt is connected, we can use SQL statements to query and update data. Use the command line to import CSV files, commit changes, push them to remote or merge team members’ changes. All git commands are tried out and completely consistent for dolt. Dolt feels like a child of GIT and mysql. Dolt has the following commands:
$ dolt Valid commands for dolt are init - Create a dolt data warehouse status - View workspace status add - Add and modify to staging area reset - Removes the modification of the staging area commit - Submit to warehouse sql - Run an SQL command in the warehouse sql-server - Start MySQL compatible server log - View the submission log diff - Comparison table blame - View the user and version number last modified in each row of the table E merge - Merge branches branch - Create, view, edit, or delete branches tag - Create, view, edit, or delete labels checkout - Switch a branch or overwrite a table remote - Manage remote warehouse push - Push to remote warehouse pull - Pull and merge remote warehouse data fetch - Update data from remote warehouse clone - Clone remote warehouse data creds - Management of identity certificate login - Log in to the remote dolt host version - View dolt version config - Dolt related configurations ls - View tables in the workspace schema - View or import table structure table - Copy, rename, delete, or export tables conflicts - View and resolve merge conflicts migrate - Perform repository migration to update to the latest format read-tables - Extract tables from a specific submission into a new warehouse gc - Clear unreferenced data from the warehouse
- Install on Linux or Mac using the following command:
sudo bash -c 'curl -L https://github.com/dolthub/dolt/releases/latest/download/install.sh | bash'
- Install using homebrew:
brew install dolt
- You can download the MSI file for windows installation and run it directly
- The source code installation depends on the go environment. After cloning the GitHub source code, enter the go folder and run the following command:
go install ./cmd/dolt
Take the storage of state population data as an example to briefly introduce the use of dolt.
$ mkdir state-pops $ cd state-pops
- Execute dolt init to create a dolt warehouse and run SQL statements to add data
$ 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
- Use dolt SQL to enter the SQL command window, or use – Q to execute SQL statements directly
$ dolt sql -q "select * from state_populations where state = 'New York'" +----------+------------+ | state | population | +----------+------------+ | New York | 340120 | +----------+------------+
- Add a new table and submit it. Each command has the same meaning as git, except dolt is for tables and Git is for files
$ dolt add . $ dolt commit -m "initial data" $ dolt status On branch master nothing to commit, working tree clean
- Use SQL to update the table. This time, enter the SQL command window to execute:
$ 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
- Use diff to see what has changed:
$ 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 | +-----+---------------+------------+
- Submit modification:
$ dolt add state_populations $ dolt commit -m "More like Old Jersey"
- To import data, use dolt table import to import CSV or JSON data- The U option means to import data into an existing table, – C means to create a table and import data:
$ head -n3 data.csv state,population Delaware,59096 Maryland,319728 $ dolt table import -c -pk=state state_populations data.csv
- Just like git, it is better to modify it on its own branch and then merge it into the master
$ dolt checkout -b <branch> $ dolt merge <branch>
- Dolt also supports remote warehouse management. When clone data, the remote warehouse will automatically establish association
$ dolt clone dolthub/corona-virus ... $ cd corona-virus $ dolt remote -v origin https://doltremoteapi.dolthub.com/dolthub/corona-virus
- If the warehouse is created locally, you can also push it to the remote end and create a remote warehouse
$ dolt remote add origin myname/myRepo $ dolt remote -v origin https://doltremoteapi.dolthub.com/myname/myRepo $ dolt push origin master
Open source outpostShare popular, interesting and practical open source projects on a daily basis. Participate in maintaining the open source technology resource library of 100000 + star, including python, Java, C / C + +, go, JS, CSS, node.js, PHP,. Net, etc.