Skip to content

Commit e21f811

Browse files
author
cg33
authored
Merge pull request #565 from wayyoungboy/master
support OceanBase
2 parents 54edfd1 + ce8b398 commit e21f811

File tree

14 files changed

+317
-8
lines changed

14 files changed

+317
-8
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ $ adm init web
8585
- [mssql](https://raw.githubusercontent.com/GoAdminGroup/go-admin/master/data/admin.mssql)
8686
- [postgresql](https://raw.githubusercontent.com/GoAdminGroup/go-admin/master/data/admin.pgsql)
8787
- [sqlite](https://raw.githubusercontent.com/GoAdminGroup/go-admin/master/data/admin.db)
88+
- [OceanBase](https://raw.githubusercontent.com/GoAdminGroup/go-admin/master/data/admin.sql)
89+
8890

8991
### Step 2: create main.go
9092

adm/cli.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
package main
66

77
import (
8+
"fmt"
89
_ "github.com/GoAdminGroup/go-admin/modules/db/drivers/mysql"
10+
_ "github.com/GoAdminGroup/go-admin/modules/db/drivers/oceanbase"
911
_ "github.com/GoAdminGroup/go-admin/modules/db/drivers/postgres"
1012
_ "github.com/GoAdminGroup/go-admin/modules/db/drivers/sqlite"
11-
12-
"fmt"
1313
"os"
1414
"runtime"
1515
"runtime/debug"

adm/project_web.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,14 @@ func buildProjectWeb(port string) {
138138
_, _ = w.Write([]byte(`{"code": 400, "msg": "` + local(lang)("web.wrong parameter") + `: ` + field + `"}`))
139139
return
140140
}
141+
} else if r.PostFormValue("db_type") == "oceanbase" {
142+
if field, ok := checkEmpty([]string{"db_port", "db_host", "db_user", "db_name"}, r); !ok {
143+
w.WriteHeader(http.StatusOK)
144+
w.Header().Add("Content-Type", "application/json")
145+
_, _ = w.Write([]byte(`{"code": 400, "msg": "` + local(lang)("web.wrong parameter") + `: ` + field + `"}`))
146+
return
147+
}
148+
141149
} else {
142150
if field, ok := checkEmpty([]string{"db_port", "db_host", "db_user", "db_passwd", "db_name"}, r); !ok {
143151
w.WriteHeader(http.StatusOK)
@@ -242,6 +250,8 @@ func buildProjectWeb(port string) {
242250
if err := http.Serve(l, nil); err != nil {
243251
log.Fatal("ListenAndServe: ", err)
244252
}
253+
fmt.Println("GoAdmin web install program start.")
254+
245255
}(startChan)
246256

247257
<-startChan

adm/project_web.tmpl.go

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ var projectWebTmpl = `
191191
<div class="item" data-value="postgresql">PostgreSQL</div>
192192
<div class="item" data-value="mssql">MSSQL</div>
193193
<div class="item" data-value="sqlite">SQLite3</div>
194+
<div class="item" data-value="oceanbase">OceanBase</div>
195+
194196
</div>
195197
</div>
196198
</div>
@@ -233,7 +235,29 @@ var projectWebTmpl = `
233235
<span class="help">{{local "web.the file path of sqlite3 database"}}<br>{{local "web.please use absolute path when you start as service"}}</span>
234236
</div>
235237
</div>
236-
238+
<div id="oceanbase_settings" class="hide">
239+
<div class="inline required field ">
240+
<label for="db_host">{{local "web.database host"}}</label>
241+
<input id="db_host" name="db_host" value="127.0.0.1">
242+
</div>
243+
<div class="inline required field ">
244+
<label for="db_port">{{local "web.database port"}}</label>
245+
<input id="db_port" name="db_port" value="2883">
246+
</div>
247+
<div class="inline required field ">
248+
<label for="db_user">{{local "web.database user"}}</label>
249+
<input id="db_user" name="db_user" value="root@sys">
250+
</div>
251+
<div class="inline required field ">
252+
<label for="db_passwd">{{local "web.database password"}}</label>
253+
<input id="db_passwd" name="db_passwd" type="password" value="">
254+
</div>
255+
<div class="inline required field ">
256+
<label for="db_name">{{local "web.database name"}}</label>
257+
<input id="db_name" name="db_name" value="goadmin">
258+
<span class="help">{{local "web.where the framework sql data install to"}}</span>
259+
</div>
260+
</div>
237261
<h4 class="ui dividing header">{{local "web.installation settings"}}</h4>
238262
239263
<div class="inline required field ">
@@ -370,6 +394,9 @@ var projectWebTmpl = `
370394
<li>
371395
<a href="https://gitee.com/go-admin/go-admin/raw/master/data/admin.db" target="_blank">SQLite3</a>
372396
</li>
397+
<li>
398+
<a href="https://gitee.com/go-admin/go-admin/raw/master/data/admin.sql" target="_blank">OceanBase</a>
399+
</li>
373400
</ul>
374401
<p>
375402
2. 依次执行以下命令:
@@ -455,6 +482,10 @@ var projectWebTmpl = `
455482
<a href="https://raw.githubusercontent.com/GoAdminGroup/go-admin/master/data/admin.db"
456483
target="_blank">SQLite3</a>
457484
</li>
485+
<li>
486+
<a href="https://raw.githubusercontent.com/GoAdminGroup/go-admin/master/data/admin.sql"
487+
target="_blank">OceanBase</a>
488+
</li>
458489
</ul>
459490
<p>
460491
2. Execute the following command in turn
@@ -587,6 +618,11 @@ var projectWebTmpl = `
587618
"addr": "127.0.0.1",
588619
"port": "1433",
589620
"user": "sa"
621+
},
622+
"oceanbase": {
623+
"addr": "127.0.0.1",
624+
"port": "2881",
625+
"user": "root@sys"
590626
}
591627
};
592628

engine/engine.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,11 @@ func (eng *Engine) SqliteConnection() db.Connection {
260260
return db.GetConnectionFromService(eng.Services.Get(db.DriverSqlite))
261261
}
262262

263+
// OceanBaseConnection return the OceanBase db connection of given driver.
264+
func (eng *Engine) OceanBaseConnection() db.Connection {
265+
return db.GetConnectionFromService(eng.Services.Get(db.DriverOceanBase))
266+
}
267+
263268
type ConnectionSetter func(db.Connection)
264269

265270
// ResolveConnection resolve the specified driver connection.

go.mod

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,29 @@ go 1.13
44

55
require (
66
github.com/360EntSecGroup-Skylar/excelize v1.4.1
7+
github.com/AlecAivazis/survey/v2 v2.3.6 // indirect
78
github.com/GoAdminGroup/html v0.0.1
89
github.com/NebulousLabs/fastrand v0.0.0-20181203155948-6fb6489aac4e
910
github.com/denisenkom/go-mssqldb v0.0.0-20200206145737-bbfc9a55622e
1011
github.com/go-sql-driver/mysql v1.5.0
1112
github.com/google/uuid v1.3.0 // indirect
13+
github.com/jawher/mow.cli v1.2.0 // indirect
14+
github.com/jteeuwen/go-bindata v3.0.7+incompatible // indirect
1215
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
1316
github.com/lib/pq v1.3.0
1417
github.com/magiconair/properties v1.8.1
1518
github.com/mattn/go-colorable v0.1.4 // indirect
1619
github.com/mattn/go-sqlite3 v2.0.3+incompatible
1720
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b
1821
github.com/natefinch/lumberjack v2.0.0+incompatible
22+
github.com/schollz/progressbar v1.0.0 // indirect
1923
github.com/sirupsen/logrus v1.4.2
2024
github.com/stretchr/objx v0.2.0 // indirect
21-
github.com/stretchr/testify v1.5.1
25+
github.com/stretchr/testify v1.6.1
26+
github.com/tdewolff/minify/v2 v2.12.4 // indirect
2227
go.uber.org/zap v1.14.1
2328
golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d
24-
golang.org/x/sys v0.0.0-20200219091948-cb0a6d8edb6c // indirect
25-
golang.org/x/text v0.3.2
29+
golang.org/x/text v0.3.3
2630
google.golang.org/appengine v1.6.5 // indirect
2731
gopkg.in/ini.v1 v1.51.0
2832
gopkg.in/yaml.v2 v2.2.8

0 commit comments

Comments
 (0)