Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support plugin #1

Merged
merged 3 commits into from
Nov 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bin
21 changes: 21 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
override DOCKER = $(shell which docker)
override GIT_VERSION = $(shell git rev-parse --abbrev-ref HEAD)${CUSTOM} $(shell git rev-parse HEAD)
override PROJECT_NAME = sqle-oracle-plugin
override LDFLAGS = -ldflags "-X 'main.version=\"${GIT_VERSION}\"'"
override GOBIN = ${shell pwd}/bin

GO_COMPILER_IMAGE ?= golang:1.16

# Copy from SQLE
PROJECT_VERSION = $(shell if [ "$$(git tag --points-at HEAD | tail -n1)" ]; then git tag --points-at HEAD | tail -n1 | sed 's/v\(.*\)/\1/'; else git rev-parse --abbrev-ref HEAD | sed 's/release-\(.*\)/\1/' | tr '-' '\n' | head -n1; fi)

default: install

install:
go build -mod=vendor ${LDFLAGS} -o $(GOBIN)/$(PROJECT_NAME) ./

docker_install:
$(DOCKER) run -v $(shell pwd):/universe --rm $(GO_COMPILER_IMAGE) sh -c "cd /universe && make install $(MAKEFLAGS)"

upload:
curl -T $(shell pwd)/$(GOBIN)/$(PROJECT_NAME) ftp://$(RELEASE_FTPD_HOST)/actiontech-sqle/plugins/$(PROJECT_VERSION)/$(PROJECT_NAME) --ftp-create-dirs
23 changes: 23 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module github.com/actiontech/sqle-oracle-plugin

go 1.16

require (
github.com/actiontech/sqle v1.2111.0-pre3
github.com/denisenkom/go-mssqldb v0.11.0 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/golang/glog v1.0.0 // indirect
github.com/hashicorp/go-hclog v1.0.0 // indirect
github.com/hashicorp/go-plugin v1.4.3 // indirect
github.com/hashicorp/yamux v0.0.0-20211028200310-0bc27b27de87 // indirect
github.com/mattn/go-colorable v0.1.11 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
go.uber.org/atomic v1.9.0 // indirect
golang.org/x/crypto v0.0.0-20211117183948-ae814b36b871 // indirect
golang.org/x/net v0.0.0-20211116231205-47ca1ff31462 // indirect
golang.org/x/sys v0.0.0-20211117180635-dee7805ff2e1 // indirect
google.golang.org/genproto v0.0.0-20211117155847-120650a500bb // indirect
google.golang.org/grpc v1.42.0 // indirect
)
1,452 changes: 1,452 additions & 0 deletions go.sum

Large diffs are not rendered by default.

40 changes: 40 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package main

import (
"context"
"flag"
"fmt"
"strings"

"github.com/actiontech/sqle/sqle/driver"
adaptor "github.com/actiontech/sqle/sqle/pkg/driver"
)

var version string
var printVersion = flag.Bool("version", false, "Print version & exit")

func main() {
flag.Parse()

if *printVersion {
fmt.Println(version)
return
}

plugin := adaptor.NewAdaptor(&adaptor.OracleDialector{})

aviodSelectAllColumn := &driver.Rule{
Name: "aviod_select_all_column",
Desc: "避免查询所有的列",
Category: "DQL规范",
Level: driver.RuleLevelError,
}
aviodSelectAllColumnHandler := func(ctx context.Context, rule *driver.Rule, sql string) (string, error) {
if strings.Contains(sql, "select *") {
return rule.Desc, nil
}
return "", nil
}
plugin.AddRule(aviodSelectAllColumn, aviodSelectAllColumnHandler)
plugin.Serve()
}
Loading