-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from xushiwei/db
ydb: use engine
- Loading branch information
Showing
9 changed files
with
142 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI= | ||
github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= | ||
github.com/golang-jwt/jwt/v5 v5.2.0 h1:d/ix8ftRUorsN+5eMIlF4T6J8CAt9rch3My2winC1Jw= | ||
github.com/golang-jwt/jwt/v5 v5.2.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= | ||
github.com/goplus/gop v1.2.0 h1:1EOUKhr4OitJs0BtVBVVbejuUkLbXMiFparS1VW7Fhg= | ||
github.com/goplus/gop v1.2.0/go.mod h1:F4xOWRMTPCKzNBaF1gZC/JsEKtYW1+Ldwp7tyFoaOWo= | ||
github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y= | ||
github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= | ||
github.com/qiniu/x v1.13.4-0.20240205192036-55db357e2bdf h1:FCmAN2cuVQWqWd5Mkko0W6Tuc5q2DT+tuz1Ln1zvd7M= | ||
github.com/qiniu/x v1.13.4-0.20240205192036-55db357e2bdf/go.mod h1:INZ2TSWSJVWO/RuELQROERcslBwVgFG7MkTfEdaQz9E= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
import ( | ||
"time" | ||
|
||
_ "github.com/goplus/yap/ydb/mysql" | ||
_ "github.com/goplus/yap/ydb/sqlite3" | ||
) | ||
|
||
type User struct { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ package main | |
import ( | ||
"errors" | ||
"github.com/goplus/yap/ydb" | ||
_ "github.com/goplus/yap/ydb/mysql" | ||
_ "github.com/goplus/yap/ydb/sqlite3" | ||
"time" | ||
) | ||
|
||
|
@@ -37,7 +39,7 @@ type foo struct { | |
} | ||
|
||
func main() { | ||
//line ydb/demo/foo/foo_ydb.gox:80:1 | ||
//line ydb/demo/foo/foo_ydb.gox:83:1 | ||
ydb.Gopt_AppGen_Main(new(ydb.AppGen), new(foo)) | ||
} | ||
|
||
|
@@ -52,101 +54,101 @@ func Hmac(pwd string, salt string) string { | |
//line ydb/demo/foo/foo.gop:14:1 | ||
return "" | ||
} | ||
//line ydb/demo/foo/foo_ydb.gox:33 | ||
//line ydb/demo/foo/foo_ydb.gox:36 | ||
func (this *foo) Main() { | ||
//line ydb/demo/foo/foo_ydb.gox:33:1 | ||
//line ydb/demo/foo/foo_ydb.gox:36:1 | ||
this.Engine__0("mysql") | ||
//line ydb/demo/foo/foo_ydb.gox:35:1 | ||
//line ydb/demo/foo/foo_ydb.gox:38:1 | ||
ydb.Gopt_Sql_Gopx_Table[User](this, "user v0.1.0") | ||
//line ydb/demo/foo/foo_ydb.gox:37:1 | ||
//line ydb/demo/foo/foo_ydb.gox:40:1 | ||
ydb.Gopt_Sql_Gopx_Table[Article](this, "v0.1.0") | ||
//line ydb/demo/foo/foo_ydb.gox:38:1 | ||
//line ydb/demo/foo/foo_ydb.gox:41:1 | ||
this.From("oldart v0.9.1", func() { | ||
}) | ||
//line ydb/demo/foo/foo_ydb.gox:43:1 | ||
//line ydb/demo/foo/foo_ydb.gox:46:1 | ||
ydb.Gopt_Sql_Gopx_Table[Tag](this, "v0.1.0") | ||
//line ydb/demo/foo/foo_ydb.gox:45:1 | ||
//line ydb/demo/foo/foo_ydb.gox:48:1 | ||
this.Class("Users", func() { | ||
//line ydb/demo/foo/foo_ydb.gox:46:1 | ||
//line ydb/demo/foo/foo_ydb.gox:49:1 | ||
this.Use("user") | ||
//line ydb/demo/foo/foo_ydb.gox:48:1 | ||
//line ydb/demo/foo/foo_ydb.gox:51:1 | ||
this.Api("register", func(id string, pwd string, nickname string, email string, tel string, ctime time.Time) error { | ||
//line ydb/demo/foo/foo_ydb.gox:49:1 | ||
//line ydb/demo/foo/foo_ydb.gox:52:1 | ||
if email == "" && tel == "" { | ||
//line ydb/demo/foo/foo_ydb.gox:50:1 | ||
//line ydb/demo/foo/foo_ydb.gox:53:1 | ||
return ErrNoEmailAndTel | ||
} | ||
//line ydb/demo/foo/foo_ydb.gox:52:1 | ||
//line ydb/demo/foo/foo_ydb.gox:55:1 | ||
this.Limit__2(3, "email=?", email) | ||
//line ydb/demo/foo/foo_ydb.gox:53:1 | ||
//line ydb/demo/foo/foo_ydb.gox:56:1 | ||
this.Limit__2(3, "tel=?", tel) | ||
//line ydb/demo/foo/foo_ydb.gox:55:1 | ||
//line ydb/demo/foo/foo_ydb.gox:58:1 | ||
salt := Rand() | ||
//line ydb/demo/foo/foo_ydb.gox:56:1 | ||
//line ydb/demo/foo/foo_ydb.gox:59:1 | ||
spwd := Hmac(pwd, salt) | ||
//line ydb/demo/foo/foo_ydb.gox:57:1 | ||
//line ydb/demo/foo/foo_ydb.gox:60:1 | ||
this.Insert__1(&User{Id: id, Spwd: spwd, Salt: salt, Nickname: nickname, Email: email, Tel: tel, Ctime: ctime}) | ||
//line ydb/demo/foo/foo_ydb.gox:59:1 | ||
//line ydb/demo/foo/foo_ydb.gox:62:1 | ||
return nil | ||
}) | ||
//line ydb/demo/foo/foo_ydb.gox:61:1 | ||
//line ydb/demo/foo/foo_ydb.gox:64:1 | ||
this.Call__1("user", "pwd", "nickname", "", "", time.Now()) | ||
//line ydb/demo/foo/foo_ydb.gox:62:1 | ||
//line ydb/demo/foo/foo_ydb.gox:65:1 | ||
this.Ret__1(ErrNoEmailAndTel) | ||
//line ydb/demo/foo/foo_ydb.gox:63:1 | ||
//line ydb/demo/foo/foo_ydb.gox:66:1 | ||
this.Call__1("user", "pwd", "nickname", "[email protected]", "", time.Now()) | ||
//line ydb/demo/foo/foo_ydb.gox:64:1 | ||
//line ydb/demo/foo/foo_ydb.gox:67:1 | ||
this.Ret__0(nil) | ||
//line ydb/demo/foo/foo_ydb.gox:65:1 | ||
//line ydb/demo/foo/foo_ydb.gox:68:1 | ||
this.Call__1("user", "pwd", "nickname", "[email protected]", "13500000000", time.Now()) | ||
//line ydb/demo/foo/foo_ydb.gox:66:1 | ||
//line ydb/demo/foo/foo_ydb.gox:69:1 | ||
this.Ret__1(ydb.ErrDuplicated) | ||
//line ydb/demo/foo/foo_ydb.gox:68:1 | ||
//line ydb/demo/foo/foo_ydb.gox:71:1 | ||
this.Api("login", func(id string, pwd string) bool { | ||
//line ydb/demo/foo/foo_ydb.gox:69:1 | ||
//line ydb/demo/foo/foo_ydb.gox:72:1 | ||
var spwd, salt string | ||
//line ydb/demo/foo/foo_ydb.gox:70:1 | ||
//line ydb/demo/foo/foo_ydb.gox:73:1 | ||
this.Query__1("id=?", id) | ||
//line ydb/demo/foo/foo_ydb.gox:71:1 | ||
//line ydb/demo/foo/foo_ydb.gox:74:1 | ||
this.Ret__1("salt", &salt, "spwd", &spwd) | ||
//line ydb/demo/foo/foo_ydb.gox:72:1 | ||
//line ydb/demo/foo/foo_ydb.gox:75:1 | ||
return Hmac(pwd, salt) == spwd | ||
}) | ||
//line ydb/demo/foo/foo_ydb.gox:74:1 | ||
//line ydb/demo/foo/foo_ydb.gox:77:1 | ||
this.Call__1("", "") | ||
//line ydb/demo/foo/foo_ydb.gox:75:1 | ||
//line ydb/demo/foo/foo_ydb.gox:78:1 | ||
this.Ret__1(false) | ||
//line ydb/demo/foo/foo_ydb.gox:76:1 | ||
//line ydb/demo/foo/foo_ydb.gox:79:1 | ||
this.Call__1("user", "pwd") | ||
//line ydb/demo/foo/foo_ydb.gox:77:1 | ||
//line ydb/demo/foo/foo_ydb.gox:80:1 | ||
this.Ret__1(true) | ||
}) | ||
//line ydb/demo/foo/foo_ydb.gox:80:1 | ||
//line ydb/demo/foo/foo_ydb.gox:83:1 | ||
this.Class("Articles", func() { | ||
//line ydb/demo/foo/foo_ydb.gox:81:1 | ||
//line ydb/demo/foo/foo_ydb.gox:84:1 | ||
this.Use("article") | ||
//line ydb/demo/foo/foo_ydb.gox:83:1 | ||
//line ydb/demo/foo/foo_ydb.gox:86:1 | ||
this.Api("listByTag", func(tag string) (result []ArticleEntry) { | ||
//line ydb/demo/foo/foo_ydb.gox:84:1 | ||
//line ydb/demo/foo/foo_ydb.gox:87:1 | ||
var ids []string | ||
//line ydb/demo/foo/foo_ydb.gox:85:1 | ||
//line ydb/demo/foo/foo_ydb.gox:88:1 | ||
this.Query__1("tag.name=?", tag) | ||
//line ydb/demo/foo/foo_ydb.gox:86:1 | ||
//line ydb/demo/foo/foo_ydb.gox:89:1 | ||
this.Ret__1("tag.article", &ids) | ||
//line ydb/demo/foo/foo_ydb.gox:88:1 | ||
//line ydb/demo/foo/foo_ydb.gox:91:1 | ||
this.Query__1("id=?", ids) | ||
//line ydb/demo/foo/foo_ydb.gox:89:1 | ||
//line ydb/demo/foo/foo_ydb.gox:92:1 | ||
this.Ret__1(&result) | ||
//line ydb/demo/foo/foo_ydb.gox:90:1 | ||
//line ydb/demo/foo/foo_ydb.gox:93:1 | ||
return | ||
}) | ||
//line ydb/demo/foo/foo_ydb.gox:93:1 | ||
//line ydb/demo/foo/foo_ydb.gox:96:1 | ||
this.Api("listByAuthor", func(author string) (result []ArticleEntry) { | ||
//line ydb/demo/foo/foo_ydb.gox:94:1 | ||
//line ydb/demo/foo/foo_ydb.gox:97:1 | ||
this.Query__1("author=?", author) | ||
//line ydb/demo/foo/foo_ydb.gox:95:1 | ||
//line ydb/demo/foo/foo_ydb.gox:98:1 | ||
this.Ret__1(&result) | ||
//line ydb/demo/foo/foo_ydb.gox:96:1 | ||
//line ydb/demo/foo/foo_ydb.gox:99:1 | ||
return | ||
}) | ||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package mysql | ||
|
||
import ( | ||
"log" | ||
"os" | ||
|
||
_ "github.com/go-sql-driver/mysql" | ||
"github.com/goplus/yap/ydb" | ||
) | ||
|
||
// Register registers a default data source for `mysql` engine. | ||
func Register(defaultDataSource string) { | ||
ydb.Register("mysql", defaultDataSource) | ||
} | ||
|
||
func init() { | ||
ydb.Register("mysql", func() string { | ||
dataSource := os.Getenv("YDB_MYSQL_TEST") | ||
if dataSource == "" { | ||
log.Panicln("env `YDB_MYSQL_TEST` not found, please set it before running") | ||
} | ||
return dataSource | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package sqlite3 | ||
|
||
import ( | ||
"github.com/goplus/yap/ydb" | ||
_ "github.com/mattn/go-sqlite3" | ||
) | ||
|
||
func init() { | ||
ydb.Register("sqlite3", "file:test.db?cache=shared&mode=memory") | ||
} |