From 948b3f0b364e9abce4a4675ddd0f6022d8c8ebed Mon Sep 17 00:00:00 2001 From: zhuyasen Date: Mon, 5 Feb 2024 16:11:17 +0800 Subject: [PATCH] update docs --- README.md | 4 ++-- assets/install-cn.md | 2 +- assets/install-en.md | 2 +- assets/readme-cn.md | 7 +++++-- pkg/ggorm/README.md | 6 ++++-- pkg/ggorm/base_model.go | 2 +- pkg/ggorm/gorm.go | 19 +++++++++++++++++-- pkg/ggorm/gormLogger.go | 2 +- pkg/ggorm/gormLogger_test.go | 2 +- pkg/ggorm/gorm_test.go | 13 ++++++++++++- pkg/ggorm/option.go | 2 +- 11 files changed, 46 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 9dc2583f..2856d6a6 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ -[Sponge](https://github.com/zhufuyi/sponge) is a powerful golang productivity tool that integrates `automatic code generation`, `web and microservices frameworks`, `basic development framework`. sponge has a wealth of generating code commands, generating different functional code can be combined into a complete service (similar to the way that artificially broken sponge cells can automatically recombine into a new sponge). The code is decoupled and modularly designed, it is easy to build a complete project from development to deployment, so that you develop web or microservices project easily, golang can also be "low-code development". +**Sponge** is a basic development framework that integrates `code auto generation`, `gin and grpc`, sponge has a wealth of generating code commands, generating different functional code can be combined into a complete service (similar to the way that artificially broken sponge cells can automatically recombine into a new sponge). The code is decoupled and modularly designed, it is easy to build a complete project from development to deployment, so that you develop web or microservices project easily, Go can also be "low-code development".
@@ -47,7 +47,7 @@ sponge is mainly based on **SQL** and **Protobuf** two ways to generate code, ea ### Services framework -sponge generated microservice code framework is shown in the figure below, which is a typical microservice hierarchical structure, with high performance, high scalability, contains commonly used service governance features, you can easily replace or add their own service governance features. +Sponge is essentially a microservice framework that includes code generation and deployment capabilities. The microservice framework is shown in the following figure, which is a typical microservice hierarchical structure, with high performance, high scalability, contains commonly used service governance features, you can easily replace or add their own service governance features.

diff --git a/assets/install-cn.md b/assets/install-cn.md index 9fbd3cc8..631d2392 100644 --- a/assets/install-cn.md +++ b/assets/install-cn.md @@ -16,7 +16,7 @@ 下载protoc地址: [https://github.com/protocolbuffers/protobuf/releases/tag/v25.2](https://github.com/protocolbuffers/protobuf/releases/tag/v25.2) -> 要求v3.20以上版本,根据系统类型下载对应的 protoc 二进制文件,把 protoc 二进制文件移动到go二进制文件所在的目录。 +> 根据系统类型下载对应的 protoc 二进制文件,把 protoc 二进制文件移动到go二进制文件所在的目录。 查看protoc版本: `protoc --version` diff --git a/assets/install-en.md b/assets/install-en.md index 86212b3b..02f2e60a 100644 --- a/assets/install-en.md +++ b/assets/install-en.md @@ -16,7 +16,7 @@ Check go version: `go version` Download protoc from: [https://github.com/protocolbuffers/protobuf/releases/tag/v25.2](https://github.com/protocolbuffers/protobuf/releases/tag/v25.2) -> Required version: v3.20 or above. Download the protoc binaries according to the system type, move the protoc binaries to the directory where the go binaries are located. +> Download the protoc binaries according to the system type, move the protoc binaries to the directory where the go binaries are located. Check protoc version: `protoc --version` diff --git a/assets/readme-cn.md b/assets/readme-cn.md index 6061b8d0..37221962 100644 --- a/assets/readme-cn.md +++ b/assets/readme-cn.md @@ -1,4 +1,7 @@ -[sponge](https://github.com/zhufuyi/sponge) 是一个集成了`自动生成代码`、`web和微服务框架`、`基础开发框架`的golang生产力工具。sponge拥有丰富的生成代码命令,生成不同的功能代码可以组合成完整的服务(类似人为打散的海绵细胞可以自动重组成一个新的海绵)。代码解耦模块化设计,很容易构建出从开发到部署的完整工程项目,让你开发web或微服务项目轻而易举、事半功倍,golang也可以"低代码开发"。 + + + +[sponge](https://github.com/zhufuyi/sponge) 是一个集成了 `自动生成代码`、`gin和grpc` 的基础开发框架。sponge拥有丰富的生成代码命令,生成不同的功能代码可以组合成完整的服务(类似人为打散的海绵细胞可以自动重组成一个新的海绵)。代码解耦模块化设计,很容易构建出从开发到部署的完整工程项目,让你开发web或微服务项目轻而易举、事半功倍,使用go也可以"低代码开发"。
@@ -30,7 +33,7 @@ sponge主要基于**SQL**和**Protobuf**两种方式生成代码,每种方式 ### 微服务框架 -sponge生成的微服务代码框架如下图所示,这是典型的微服务分层结构,具有高性能,高扩展性,包含了常用的服务治理功能,可以很方便替换或添加自己的服务治理功能。 +sponge本质是一个包含了生成代码和部署功能的微服务框架,微服务框架如下图所示,这是典型的微服务分层结构,具有高性能,高扩展性,包含了常用的服务治理功能,可以很方便替换或添加自己的服务治理功能。

diff --git a/pkg/ggorm/README.md b/pkg/ggorm/README.md index 3f849b82..927821bc 100644 --- a/pkg/ggorm/README.md +++ b/pkg/ggorm/README.md @@ -1,6 +1,8 @@ -### mysql +### ggorm -`mysql` library wrapped in [gorm](gorm.io/gorm), with added features such as tracer, paging queries, etc. +`ggorm` library wrapped in [gorm](gorm.io/gorm), with added features such as tracer, paging queries, etc. + +Support `mysql`, `postgresql`, `tidb`, `clickhouse`, `sqlite`.
diff --git a/pkg/ggorm/base_model.go b/pkg/ggorm/base_model.go index 8fb2acf9..4ab1135d 100644 --- a/pkg/ggorm/base_model.go +++ b/pkg/ggorm/base_model.go @@ -1,4 +1,4 @@ -package mysql +package ggorm import ( "reflect" diff --git a/pkg/ggorm/gorm.go b/pkg/ggorm/gorm.go index 27e55c2b..d698c8d7 100644 --- a/pkg/ggorm/gorm.go +++ b/pkg/ggorm/gorm.go @@ -1,5 +1,5 @@ -// Package mysql is a library wrapped on top of gorm.io/gorm, with added features such as link tracing, paging queries, etc. -package mysql +// Package ggorm is a library wrapped on top of gorm.io/gorm, with added features such as link tracing, paging queries, etc. +package ggorm import ( "database/sql" @@ -100,6 +100,21 @@ func InitPostgresql(dsn string, opts ...Option) (*gorm.DB, error) { return db, nil } +// InitTidb init tidb +func InitTidb(dsn string, opts ...Option) (*gorm.DB, error) { + return InitMysql(dsn, opts...) +} + +// InitClickhouse init clickhouse +//func InitClickhouse(dsn string, opts ...Option) (*gorm.DB, error) { +// return InitMysql(dsn, opts...) +//} + +// InitSqlite init sqlite +//func InitSqlite(dsn string, opts ...Option) (*gorm.DB, error) { +// panic("not implemented") +//} + // gorm setting func gormConfig(o *options) *gorm.Config { config := &gorm.Config{ diff --git a/pkg/ggorm/gormLogger.go b/pkg/ggorm/gormLogger.go index 214a1792..b5b9f1cb 100644 --- a/pkg/ggorm/gormLogger.go +++ b/pkg/ggorm/gormLogger.go @@ -1,4 +1,4 @@ -package mysql +package ggorm import ( "context" diff --git a/pkg/ggorm/gormLogger_test.go b/pkg/ggorm/gormLogger_test.go index ee3754fd..0724ac51 100644 --- a/pkg/ggorm/gormLogger_test.go +++ b/pkg/ggorm/gormLogger_test.go @@ -1,4 +1,4 @@ -package mysql +package ggorm import ( "context" diff --git a/pkg/ggorm/gorm_test.go b/pkg/ggorm/gorm_test.go index 0f0fab75..4cde0abd 100644 --- a/pkg/ggorm/gorm_test.go +++ b/pkg/ggorm/gorm_test.go @@ -1,4 +1,4 @@ -package mysql +package ggorm import ( "fmt" @@ -21,6 +21,17 @@ func TestInitMysql(t *testing.T) { t.Logf("%+v", db.Name()) } +func TestInitTidb(t *testing.T) { + db, err := InitTidb(dsn) + if err != nil { + // ignore test error about not being able to connect to real tidb + t.Logf(fmt.Sprintf("connect to mysql failed, err=%v, dsn=%s", err, dsn)) + return + } + + t.Logf("%+v", db.Name()) +} + func TestInitPostgresql(t *testing.T) { dsn = "host=192.168.3.37 user=root password=123456 dbname=account port=5432 sslmode=disable TimeZone=Asia/Shanghai" db, err := InitPostgresql(dsn, WithEnableTrace()) diff --git a/pkg/ggorm/option.go b/pkg/ggorm/option.go index d5a2b9c6..c4a4c194 100644 --- a/pkg/ggorm/option.go +++ b/pkg/ggorm/option.go @@ -1,4 +1,4 @@ -package mysql +package ggorm import ( "time"