sql-formatter-org / sql-formatter

A whitespace formatter for different query languages
https://sql-formatter-org.github.io/sql-formatter/
MIT License
2.37k stars 405 forks source link

Initial TiDB Support #724

Closed dveeden closed 8 months ago

dveeden commented 8 months ago

Closes #723

codesandbox-ci[bot] commented 8 months ago

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

dveeden commented 8 months ago

I personally have zero knowledge of this dialect. Actually, up to this day I didn't even know it existed.

If you want to get some hands on experience, there are a few options. For production deployments you'll need multiple components, but for testing this isn't required, which makes this a lot easier.

Option 1: Docker

docker run -it --rm -p 4000:4000 pingcap/tidb

This runs TiDB on port 4000. Connect with mysql -h 127.0.0.1 -P 4000 -u root test.

Option 2: TiUP

curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh
tiup playground

This runs a full cluster locally on your machine, including dashboards etc. See also https://tiup.io

Option 3: TiDB Cloud

https://tidbcloud.com has a free tier.

Option 4: Build and run TiDB locally.

git clone git@github.com:pingcap/tidb.git
cd tidb
make server
./bin/tidb-server

This runs TiDB on port 4000. Connect with mysql -h 127.0.0.1 -P 4000 -u root test.

TiDB implements the MySQL protocol and syntax. See https://docs.pingcap.com/tidb/stable/mysql-compatibility for details on compatibility. There are some TiDB specific functions: https://docs.pingcap.com/tidb/stable/tidb-functions and some other things like support for sequences which are not in MySQL. Note that MariaDB also has sequences support.

dveeden commented 8 months ago

https://github.com/pingcap/tidb/blob/master/pkg/parser/parser.y might be a useful resource.