diff --git a/.CHANGELOG.md b/.CHANGELOG.md index 9f9fec5..70095e0 100644 --- a/.CHANGELOG.md +++ b/.CHANGELOG.md @@ -1,31 +1,32 @@ -## Developing -- [Init Project](https://github.com/gotomicro/eql/pull/1) -- [Selector Definition](https://github.com/gotomicro/eql/pull/2) -- [Deleter Definition](https://github.com/gotomicro/eql/pull/4) -- [Updater Definition](https://github.com/gotomicro/eql/pull/8) -- [Rft: remove NilAsNullFunc](https://github.com/gotomicro/eql/pull/48) -- [Metadata API](https://github.com/gotomicro/eql/pull/16) -- [Add model register examples](https://github.com/gotomicro/eql/pull/54) -- [tagMetaRegistry: default implementation of MetaRegistry](https://github.com/gotomicro/eql/pull/25) -- [Rft: remove defaultRegistry](https://github.com/gotomicro/eql/pull/46) -- [Use `bytebufferpool` for builder](https://github.com/gotomicro/eql/pull/39) -- [Refactor: move Insert function into db.file](https://github.com/gotomicro/eql/pull/28) -- [Selector implementation, excluding WHERE and HAVING clauses](https://github.com/gotomicro/eql/pull/32) -- [Ignore columns by Tag and Option](https://github.com/gotomicro/eql/pull/49) -- [Selector WHERE clause](https://github.com/gotomicro/eql/pull/40) -- [Support Aggregate Functions](https://github.com/gotomicro/eql/pull/37) -- [Updater implementation, excluding WHERE clause](https://github.com/gotomicro/eql/pull/36) -- [Force test and lint in pre-push](https://github.com/gotomicro/eql/pull/35) -- [Insert implementation ](https://github.com/gotomicro/eql/pull/38) -- [Delete implementation ](https://github.com/gotomicro/eql/pull/43) -- [Having implementation ](https://github.com/gotomicro/eql/pull/45) -- [RawExpr accepts arguments ](https://github.com/gotomicro/eql/pull/53) -- [Support having with alias functions](https://github.com/gotomicro/eql/pull/55) -- [Add `NewSelector` function](https://github.com/gotomicro/eql/pull/56) -- [Support using `RawExpr` as `Predicate`](https://github.com/gotomicro/eql/pull/57) -- [Remove WithNil and WithZero function](https://github.com/gotomicro/eql/pull/58) +## 开发中: +- [Init Project](https://github.com/gotomicro/eorm/pull/1) +- [Selector Definition](https://github.com/gotomicro/eorm/pull/2) +- [Deleter Definition](https://github.com/gotomicro/eorm/pull/4) +- [Updater Definition](https://github.com/gotomicro/eorm/pull/8) +- [Rft: remove NilAsNullFunc](https://github.com/gotomicro/eorm/pull/48) +- [Metadata API](https://github.com/gotomicro/eorm/pull/16) +- [Add model register examples](https://github.com/gotomicro/eorm/pull/54) +- [tagMetaRegistry: default implementation of MetaRegistry](https://github.com/gotomicro/eorm/pull/25) +- [Rft: remove defaultRegistry](https://github.com/gotomicro/eorm/pull/46) +- [Use `bytebufferpool` for builder](https://github.com/gotomicro/eorm/pull/39) +- [Refactor: move Insert function into db.file](https://github.com/gotomicro/eorm/pull/28) +- [Selector implementation, excluding WHERE and HAVING clauses](https://github.com/gotomicro/eorm/pull/32) +- [Ignore columns by Tag and Option](https://github.com/gotomicro/eorm/pull/49) +- [Selector WHERE clause](https://github.com/gotomicro/eorm/pull/40) +- [Support Aggregate Functions](https://github.com/gotomicro/eorm/pull/37) +- [Updater implementation, excluding WHERE clause](https://github.com/gotomicro/eorm/pull/36) +- [Force test and lint in pre-push](https://github.com/gotomicro/eorm/pull/35) +- [Insert implementation ](https://github.com/gotomicro/eorm/pull/38) +- [Delete implementation ](https://github.com/gotomicro/eorm/pull/43) +- [Having implementation ](https://github.com/gotomicro/eorm/pull/45) +- [RawExpr accepts arguments ](https://github.com/gotomicro/eorm/pull/53) +- [Support having with alias functions](https://github.com/gotomicro/eorm/pull/55) +- [Add `NewSelector` function](https://github.com/gotomicro/eorm/pull/56) +- [Support using `RawExpr` as `Predicate`](https://github.com/gotomicro/eorm/pull/57) +- [Remove WithNil and WithZero function](https://github.com/gotomicro/eorm/pull/58) +- [改名为 eorm, 并且改为纯中文项目](https://github.com/gotomicro/eorm/pull/59) -### Docs, Lint issues and Examples -- [Add examples and docs for Aggregate and Assign](https://github.com/gotomicro/eql/pull/50) -- [Add examples for Column and columns](https://github.com/gotomicro/eql/pull/51) -- [Add examples for DB, Predicate, Deleter, Inserter](https://github.com/gotomicro/eql/pull/52) \ No newline at end of file +### 文档, 代码质量以及文档 +- [Add examples and docs for Aggregate and Assign](https://github.com/gotomicro/eorm/pull/50) +- [Add examples for Column and columns](https://github.com/gotomicro/eorm/pull/51) +- [Add examples for DB, Predicate, Deleter, Inserter](https://github.com/gotomicro/eorm/pull/52) \ No newline at end of file diff --git a/.deepsource.toml b/.deepsource.toml index cc8dd95..22cf3dd 100644 --- a/.deepsource.toml +++ b/.deepsource.toml @@ -19,7 +19,7 @@ name = "go" enabled = true [analyzers.meta] - import_root = "github.com/gotomicro/eql" + import_root = "github.com/gotomicro/eorm" dependencies_vendored = false [[analyzers]] diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 8775d05..940ce30 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -9,7 +9,7 @@ assignees: '' #### English Only -Please check [existing issues](https://github.com/gotomicro/eql/issues) first to avoid duplication and answer the questions below before submitting your issue. +Please check [existing issues](https://github.com/gotomicro/eorm/issues) first to avoid duplication and answer the questions below before submitting your issue. ### Issue Type diff --git a/.github/ISSUE_TEMPLATE/enhancement-request.md b/.github/ISSUE_TEMPLATE/enhancement-request.md index dfb7da2..582d8a1 100644 --- a/.github/ISSUE_TEMPLATE/enhancement-request.md +++ b/.github/ISSUE_TEMPLATE/enhancement-request.md @@ -9,7 +9,7 @@ assignees: '' #### English Only -Please check [existing issues](https://github.com/gotomicro/eql/issues) first to avoid duplication and answer the questions below before submitting your issue. +Please check [existing issues](https://github.com/gotomicro/eorm/issues) first to avoid duplication and answer the questions below before submitting your issue. Please take note Enhancement is a suggestion to existing features and codebase. If you're requesting for a new feature, please select Feature. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index 4b4dc04..9ae7cd0 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -9,7 +9,7 @@ assignees: '' #### English Only -Please check [existing issues](https://github.com/gotomicro/eql/issues) first to avoid duplication and answer the questions below before submitting your issue. +Please check [existing issues](https://github.com/gotomicro/eorm/issues) first to avoid duplication and answer the questions below before submitting your issue. ### Use case(s) diff --git a/.github/ISSUE_TEMPLATE/question.md b/.github/ISSUE_TEMPLATE/question.md index 8dc7cd9..33c5c0b 100644 --- a/.github/ISSUE_TEMPLATE/question.md +++ b/.github/ISSUE_TEMPLATE/question.md @@ -9,7 +9,7 @@ assignees: '' #### English Only -Please check [existing issues](https://github.com/gotomicro/eql/issues) first to avoid duplication and answer the questions below before submitting your issue. +Please check [existing issues](https://github.com/gotomicro/eorm/issues) first to avoid duplication and answer the questions below before submitting your issue. ### What version of EQL are you using? diff --git a/.github/linters/.golangci.yml b/.github/linters/.golangci.yml index fa7a0cf..fbeb8c1 100644 --- a/.github/linters/.golangci.yml +++ b/.github/linters/.golangci.yml @@ -53,6 +53,6 @@ linters: linters-settings: gci: - local-prefixes: github.com/gotomicro/eql + local-prefixes: github.com/gotomicro/eorm goimports: - local-prefixes: github.com/gotomicro/eql + local-prefixes: github.com/gotomicro/eorm diff --git a/README.md b/README.md index f5a0556..37caba9 100644 --- a/README.md +++ b/README.md @@ -1,34 +1,30 @@ -# EQL +# EORM -[![codecov](https://codecov.io/gh/gotomicro/eql/branch/main/graph/badge.svg?token=vc0BDor3Lk)](https://codecov.io/gh/gotomicro/eql) +[![codecov](https://codecov.io/gh/gotomicro/eorm/branch/main/graph/badge.svg?token=vc0BDor3Lk)](https://codecov.io/gh/gotomicro/eorm) -An easy-use SQL builder. +简单的 ORM 框架。 -## SQL 2003 Standard -In theory, we try to support the [SQL 2003 standard](https://ronsavage.github.io/SQL/sql-2003-2.bnf.html#query%20specification). But as we know, some databases do not follow the standard. These databases have its own feature, and we will support these grammers in the future. +> 注意:这是一个全中文的仓库。这意味着注释、文档和错误信息,都会是中文的。介意的用户可以选择 GORM,这也是一个杰出的 ORM 仓库 -## Design +## SQL 2003 标准 +理论上来说,我们计划支持 [SQL 2003 standard](https://ronsavage.github.io/SQL/sql-2003-2.bnf.html#query%20specification). 不过据我们所知,并不是所有的数据库都支持全部的 SQL 2003 标准,所以用户还是需要进一步检查目标数据库的语法。 -We are not English native speaker, so we use Chinese to write the design documents. We plan to translate them to English. Or you can use some software to translate it. - -Here is a good one: https://www.deepl.com/en/translator +## 设计 [设计思路](./docs/design.md) -[B站视频](https://space.bilibili.com/324486985) - -## Contribution +## 加入我们 -You must follow these rules: -- One commit one PR -- You must add change log to `.CHANGELOG.md` file -- You must add license header to every new files +我们欢迎任何人给我们提合并请求,但是我们希望合并请求能够做到: +- 一个合并请求一个 Commit ID +- 自己要先确保合并请求能够通过 CI +- 我们使用 uber 的[代码风格](https://github.com/uber-go/guide/blob/master/style.md) -[style guide](https://github.com/uber-go/guide/blob/master/style.md) +### 设置开发环境 -### Setup Develop Environment +如果你是 Windows 用户,那么我们建议你使用 WSL,因为这个仓库会使用到一个 Unix 命令来帮助构建、测试等。 -#### install golangci-lint -Please refer [Install golangci-lint](https://golangci-lint.run/usage/install/) -#### setup pre-push github hook -Please move the `.github/pre-push` to your `.git` directory \ No newline at end of file +#### 安装 golangci-lint +参考 [Install golangci-lint](https://golangci-lint.run/usage/install/) +#### 设置 pre-push github hook +将`.github/pre-push` 复制到本仓库的 `.git` 目录下 \ No newline at end of file diff --git a/aggregate.go b/aggregate.go index b40c3e6..28bec60 100644 --- a/aggregate.go +++ b/aggregate.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package eql +package eorm // Aggregate represents aggregate expression, including AVG, MAX, MIN... type Aggregate struct { diff --git a/aggregate_test.go b/aggregate_test.go index 8243627..74e6aba 100644 --- a/aggregate_test.go +++ b/aggregate_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package eql +package eorm import ( "fmt" diff --git a/assignment.go b/assignment.go index 94c0b73..b5d802d 100644 --- a/assignment.go +++ b/assignment.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package eql +package eorm // Assignable represents that something could be used as "assignment" statement type Assignable interface { diff --git a/assignment_test.go b/assignment_test.go index fd7cf20..1e30ad7 100644 --- a/assignment_test.go +++ b/assignment_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package eql +package eorm import "fmt" diff --git a/builder.go b/builder.go index 4c84e56..e9d6480 100644 --- a/builder.go +++ b/builder.go @@ -12,11 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -package eql +package eorm import ( "errors" - "github.com/gotomicro/eql/internal" + "github.com/gotomicro/eorm/internal" "github.com/valyala/bytebufferpool" ) @@ -43,21 +43,21 @@ type builder struct { aliases map[string]struct{} } -func (b builder) quote(val string) { +func (b *builder) quote(val string) { _ = b.buffer.WriteByte(b.dialect.quote) _, _ = b.buffer.WriteString(val) _ = b.buffer.WriteByte(b.dialect.quote) } -func (b builder) space() { +func (b *builder) space() { _ = b.buffer.WriteByte(' ') } -func (b builder) end() { +func (b *builder) end() { _ = b.buffer.WriteByte(';') } -func (b builder) comma() { +func (b *builder) comma() { _ = b.buffer.WriteByte(',') } diff --git a/builder_test.go b/builder_test.go index d768ef0..3eddc56 100644 --- a/builder_test.go +++ b/builder_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package eql +package eorm import "fmt" diff --git a/column.go b/column.go index 22768f7..0b09fcb 100644 --- a/column.go +++ b/column.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package eql +package eorm // Column represents column // it could have alias diff --git a/column_test.go b/column_test.go index a662368..ceeb4ce 100644 --- a/column_test.go +++ b/column_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package eql +package eorm import "fmt" diff --git a/db.go b/db.go index 50a4c54..b405653 100644 --- a/db.go +++ b/db.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package eql +package eorm import ( "github.com/valyala/bytebufferpool" diff --git a/db_test.go b/db_test.go index 2dd250c..ffe2050 100644 --- a/db_test.go +++ b/db_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package eql +package eorm import ( "fmt" diff --git a/delete.go b/delete.go index c7df378..87fd113 100644 --- a/delete.go +++ b/delete.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package eql +package eorm // Deleter builds DELETE query type Deleter struct { @@ -54,7 +54,7 @@ func (d *Deleter) From(table interface{}) *Deleter { } // Where accepts predicates -func (d *Deleter) Where(predicates...Predicate) *Deleter { +func (d *Deleter) Where(predicates ...Predicate) *Deleter { d.where = predicates return d -} \ No newline at end of file +} diff --git a/delete_test.go b/delete_test.go index e9826fe..a8a4125 100644 --- a/delete_test.go +++ b/delete_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package eql +package eorm import ( "fmt" diff --git a/dialect.go b/dialect.go index 6426839..9678f3e 100644 --- a/dialect.go +++ b/dialect.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package eql +package eorm // Dialect specify config or behavior of special SQL dialects type Dialect struct { diff --git a/expression.go b/expression.go index 512261a..0b19d80 100644 --- a/expression.go +++ b/expression.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package eql +package eorm // Expr is the top interface. It represents everything. type Expr interface { diff --git a/expression_test.go b/expression_test.go index 985de9f..e6c4131 100644 --- a/expression_test.go +++ b/expression_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package eql +package eorm import ( "fmt" diff --git a/go.mod b/go.mod index a5a3089..a413123 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/gotomicro/eql +module github.com/gotomicro/eorm go 1.17 diff --git a/insert.go b/insert.go index c4e2024..ea2abff 100644 --- a/insert.go +++ b/insert.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package eql +package eorm import ( "errors" diff --git a/insert_test.go b/insert_test.go index bc0bb1c..2ecab62 100644 --- a/insert_test.go +++ b/insert_test.go @@ -11,7 +11,7 @@ // 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 eql +package eorm import ( "errors" diff --git a/model.go b/model.go index b0acf73..da6b792 100644 --- a/model.go +++ b/model.go @@ -12,14 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -package eql +package eorm import ( "reflect" "strings" "sync" - "github.com/gotomicro/eql/internal" + "github.com/gotomicro/eorm/internal" ) // TableMeta represents data model, or a table diff --git a/model_test.go b/model_test.go index 1e685d8..c0d3092 100644 --- a/model_test.go +++ b/model_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package eql +package eorm import ( "fmt" diff --git a/predicate.go b/predicate.go index f66c56f..ad40554 100644 --- a/predicate.go +++ b/predicate.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package eql +package eorm type op struct { symbol string diff --git a/predicate_test.go b/predicate_test.go index 861473f..0b683f8 100644 --- a/predicate_test.go +++ b/predicate_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package eql +package eorm import ( "fmt" diff --git a/select.go b/select.go index e544d91..dd46d15 100644 --- a/select.go +++ b/select.go @@ -12,10 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -package eql +package eorm import ( - "github.com/gotomicro/eql/internal" + "github.com/gotomicro/eorm/internal" "github.com/valyala/bytebufferpool" ) @@ -193,7 +193,7 @@ func (s *Selector) selectAggregate(aggregate Aggregate) error { s.quote(cMeta.columnName) _ = s.buffer.WriteByte(')') if aggregate.alias != "" { - if _,ok :=s.aliases[aggregate.alias]; ok{ + if _, ok := s.aliases[aggregate.alias]; ok { _, _ = s.buffer.WriteString(" AS ") s.quote(aggregate.alias) } diff --git a/select_test.go b/select_test.go index 68de391..53ea32d 100644 --- a/select_test.go +++ b/select_test.go @@ -12,11 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -package eql +package eorm import ( "fmt" - "github.com/gotomicro/eql/internal" + "github.com/gotomicro/eorm/internal" "github.com/stretchr/testify/assert" "testing" ) @@ -109,14 +109,14 @@ func TestSelectable(t *testing.T) { wantSql: "SELECT `id`,`first_name`,`age`,`last_name` FROM `test_model` GROUP BY `first_name`;", }, { - name: "alias in having", - builder: NewSelector(db).Select(Columns("Id"), Columns("FirstName"),Avg("Age").As("avg_age")).From(&TestModel{}).GroupBy("FirstName").Having(C("avg_age").LT(20)), - wantSql: "SELECT `id`,`first_name`,AVG(`age`) AS `avg_age` FROM `test_model` GROUP BY `first_name` HAVING `avg_age`