Skip to content

Commit

Permalink
Merge branch 'master' into pr/95
Browse files Browse the repository at this point in the history
  • Loading branch information
mattn committed Dec 30, 2023
2 parents 0df5c31 + b25c184 commit 9f71ca2
Show file tree
Hide file tree
Showing 16 changed files with 603 additions and 487 deletions.
122 changes: 103 additions & 19 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,26 +1,110 @@
name: goreleaser

name: Release
on:
pull_request:
push:
tags:
- 'v*'
env:
GO_VERSION: stable

jobs:
goreleaser:
build_for_linux:
name: Build for Linux
runs-on: ubuntu-latest
steps:
- name: Install build dependencies
run: |
sudo apt-get -qq update
sudo apt-get install -y --no-install-recommends \
build-essential
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}
- name: Build amd64
env:
CGO_ENABLED: 1
GOOS: linux
GOARCH: amd64
run: make release
- name: Archive artifacts
uses: actions/upload-artifact@v3
with:
name: dist-linux
path: sqls-linux-*.zip

build_for_macos:
name: Build for MacOS
runs-on: macos-latest
steps:
- name: Install build dependencies
run: brew install coreutils
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}
- name: Build amd64
env:
CGO_ENABLED: 1
GOOS: darwin
GOARCH: amd64
run: make release
- name: Archive artifacts
uses: actions/upload-artifact@v3
with:
name: dist-darwin
path: sqls-darwin-*.zip

build_for_windows:
name: Build for Windows
runs-on: windows-latest
steps:
- name: Install build dependencies
run: choco install zip
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}
- name: Build amd64
shell: bash
env:
CGO_ENABLED: 1
GOOS: windows
GOARCH: amd64
run: make release
- name: Archive artifacts
uses: actions/upload-artifact@v3
with:
name: dist-windows
path: sqls-windows-*.zip

release:
name: Draft Release
needs:
- build_for_linux
- build_for_macos
- build_for_windows
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Go
uses: actions/setup-go@v3
- name: Download artifacts
uses: actions/download-artifact@v3
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
go-version: 1.21
- name: Run GoReleaser(xcgo) Snapshot
run: |
make snapshot
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Run GoReleaser(xcgo) Publish
if: startsWith(github.ref, 'refs/tags/v')
run: |
make publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
name: sqls ${{ github.ref_name }}
token: ${{ secrets.GITHUB_TOKEN }}
draft: true
generate_release_notes: true
files: dist-*/sqls*.*
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ jobs:
- name: Lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.45.2
version: v1.54
- name: Test
run: go test -coverprofile coverage.out -covermode atomic ./...
98 changes: 51 additions & 47 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,51 +1,55 @@
NAME := sqls
VERSION := $(shell git describe --tags `git rev-list --tags --max-count=1`)
REVISION := $(shell git rev-parse --short HEAD)
GOVERSION := $(go version)
GITHUB_TOKEN := $(GITHUB_TOKEN)

SRCS := $(shell find . -type f -name '*.go')
LDFLAGS := -ldflags="-s -w -X \"main.version=$(VERSION)\" -X \"main.revision=$(REVISION)\""
DIST_DIRS := find * -type d -exec

.PHONY: test
test:
go test ./...
BIN := sqls
ifeq ($(OS),Windows_NT)
BIN := $(BIN).exe
endif
VERSION := $$(make -s show-version)
CURRENT_REVISION := $(shell git rev-parse --short HEAD)
BUILD_LDFLAGS := "-s -w -X main.revision=$(CURRENT_REVISION)"
GOOS := $(shell go env GOOS)
GOBIN ?= $(shell go env GOPATH)/bin
export GO111MODULE=on

.PHONY: all
all: clean build

.PHONY: build
build: $(SRCS)
go build $(LDFLAGS) ./...
build:
go build -ldflags=$(BUILD_LDFLAGS) -o $(BIN) .

.PHONY: release
release:
go build -ldflags=$(BUILD_LDFLAGS) -o $(BIN) .
zip -r sqls-$(GOOS)-$(VERSION).zip $(BIN)

.PHONY: install
install: $(SRCS)
go install $(LDFLAGS) ./...

.PHONY: lint
lint: $(SRCS)
golangci-lint run

.PHONY: coverage
coverage:
go test -v -coverprofile=coverage.out ./...
go tool cover -html=coverage.out

.PHONY: stringer
stringer:
stringer -type Kind ./token/kind.go

.PHONY: snapshot
snapshot: $(SRCS)
docker run --rm --privileged \
-v ${PWD}:/go/src/github.com/sqls-server/sqls \
-v /var/run/docker.sock:/var/run/docker.sock \
-w /go/src/github.com/sqls-server/sqls \
mailchain/goreleaser-xcgo --snapshot --rm-dist

.PHONY: publish
publish: $(SRCS)
docker run --rm --privileged \
-e GITHUB_TOKEN=$(GITHUB_TOKEN) \
-v ${PWD}:/go/src/github.com/sqls-server/sqls \
-v /var/run/docker.sock:/var/run/docker.sock \
-w /go/src/github.com/sqls-server/sqls \
mailchain/goreleaser-xcgo --rm-dist
install:
go install -ldflags=$(BUILD_LDFLAGS) .

.PHONY: show-version
show-version: $(GOBIN)/gobump
gobump show -r .

$(GOBIN)/gobump:
go install github.com/x-motemen/gobump/cmd/gobump@latest

.PHONY: test
test: build
go test -v ./...

.PHONY: clean
clean:
go clean

.PHONY: bump
bump: $(GOBIN)/gobump
ifneq ($(shell git status --porcelain),)
$(error git workspace is dirty)
endif
ifneq ($(shell git rev-parse --abbrev-ref HEAD),master)
$(error current branch is not master)
endif
@gobump up -w .
git commit -am "bump up version to $(VERSION)"
git tag "v$(VERSION)"
git push origin master
git push origin "refs/tags/v$(VERSION)"
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ sqls aims to provide advanced intelligence for you to edit sql in your own edito
- PostgreSQL([pgx](https://github.com/jackc/pgx))
- SQLite3([go-sqlite3](https://github.com/mattn/go-sqlite3))
- MSSQL([go-mssqldb](https://github.com/denisenkom/go-mssqldb))
- H2([pgx](https://github.com/CodinGame/h2go))
- Vertica([vertica-sql-go](https://github.com/vertica/vertica-sql-go))

### Language Server Features
Expand Down Expand Up @@ -233,7 +234,7 @@ The first setting in `connections` is the default connection.
| Key | Description |
| -------------- | ------------------------------------------- |
| alias | Connection alias name. Optional. |
| driver | `mysql`, `postgresql`, `sqlite3`. Required. |
| driver | `mysql`, `postgresql`, `sqlite3`, `mssql`, `h2`. Required. |
| dataSourceName | Data source name. |
| proto | `tcp`, `udp`, `unix`. |
| user | User name |
Expand Down
107 changes: 107 additions & 0 deletions dialect/h2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package dialect

var h2Keywords = []string{
"ALL",
"AND",
"ANY",
"ARRAY",
"AS",
"ASYMMETRIC",
"AUTHORIZATION",
"BETWEEN",
"BOTH",
"CASE",
"CAST",
"CHECK",
"CONSTRAINT",
"CROSS",
"CURRENT_CATALOG",
"CURRENT_DATE",
"CURRENT_PATH",
"CURRENT_ROLE",
"CURRENT_SCHEMA",
"CURRENT_TIME",
"CURRENT_TIMESTAMP",
"CURRENT_USER",
"DAY",
"DEFAULT",
"DISTINCT",
"ELSE",
"END",
"EXCEPT",
"EXISTS",
"FALSE",
"FETCH",
"FILTER",
"FOR",
"FOREIGN",
"FROM",
"FULL",
"GROUP",
"GROUPS",
"HAVING",
"HOUR",
"IF",
"ILIKE",
"IN",
"INNER",
"INTERSECT",
"INTERVAL",
"IS",
"JOIN",
"KEY",
"LEADING",
"LEFT",
"LIKE",
"LIMIT",
"LOCALTIME",
"LOCALTIMESTAMP",
"MINUS",
"MINUTE",
"MONTH",
"NATURAL",
"NOT",
"NULL",
"OFFSET",
"ON",
"OR",
"ORDER",
"OVER",
"PARTITION",
"PRIMARY",
"QUALIFY",
"RANGE",
"REGEXP",
"RIGHT",
"ROW",
"ROWNUM",
"ROWS",
"SECOND",
"SELECT",
"SESSION_USER",
"SET",
"SOME",
"SYMMETRIC",
"SYSTEM_USER",
"TABLE",
"TO",
"TOP",
"CS",
"TRAILING",
"TRUE",
"UESCAPE",
"UNION",
"UNIQUE",
"UNKNOWN",
"USER",
"USING",
"VALUE",
"VALUES",
"WHEN",
"WHERE",
"WINDOW",
"WITH",
"YEAR",
"_ROWID_",
}

3 changes: 3 additions & 0 deletions dialect/keyword.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ const (
DatabaseDriverSQLite3 DatabaseDriver = "sqlite3"
DatabaseDriverMssql DatabaseDriver = "mssql"
DatabaseDriverOracle DatabaseDriver = "oracle"
DatabaseDriverH2 DatabaseDriver = "h2"
DatabaseDriverVertica DatabaseDriver = "vertica"
)

Expand All @@ -408,6 +409,8 @@ func DataBaseKeywords(driver DatabaseDriver) []string {
return mssqlKeywords
case DatabaseDriverOracle:
return oracleKeyWords
case DatabaseDriverH2:
return h2Keywords
case DatabaseDriverVertica:
return verticaKeywords
default:
Expand Down
Loading

0 comments on commit 9f71ca2

Please sign in to comment.