Skip to content

Commit

Permalink
新增db.Scan(struct)方法:
Browse files Browse the repository at this point in the history
- 和Select方法不同的是,Scan方法仅仅影响输出,类似GoRedis的Scan的思想,依然需要指定table,只是最后的Get或者Find方法换成本方法即可
- 传入struct{}可以解析单条,类似Find方法
- 传入[]struct{}将会解析成多条,类似Get方法

注意需要传入指针值,例如传入:&User{},而不是:User{}

避免(不是禁止的意思)使用这个方法传入Map[string]interface{}

如果你全程使用struct方法,建议你可以直接使用table().select()这样原版框架支持的模式来操作数据库,因为从代码思想和洁净度角度来看,保持业务代码风格统一也是很重要的
  • Loading branch information
tobycroft committed Nov 13, 2023
1 parent c7b331d commit 5354b57
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
31 changes: 16 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,27 +79,31 @@

## 实例文档(Wiki)

说明:*为GorosePro独有功能

- 增删改
- [增加Insert](../../wiki/Insert新增数据)
- [删除Delete](../../wiki/Delete删除数据)
- [更新Update](../../wiki/Update方法)
- [替换-Replace](../../wiki/Replace方法)
- *[替换-Replace](../../wiki/Replace方法)
- 单条查询(对象)(Map[string]interface{})
- [Find/First返回对象](../../wiki/Find-First查询返回Obj对象方法)
- 多条/联合查询([]Map[string]interface{}
- [Get/Select返回数组](../../wiki/Get-Select方法)
- [Join联合查询](../../wiki/Join-Select方法)
- [Paginator复杂的子查询分页构建](../../wiki/Paginator复杂的子查询分页构建)
- [PaginatorWG高性能分页](../../wiki/PaginatorWG多线程分页)
- *[Paginator复杂的子查询分页构建](../../wiki/Paginator复杂的子查询分页构建)
- *[PaginatorWG高性能分页](../../wiki/PaginatorWG多线程分页)
- Query方法
- [Query方法使用原生语句查询](../../wiki/Query方法)
- 嵌套事务
- [支付环境下复杂的嵌套事务实例](../../wiki/支付环境下复杂的嵌套事务)
- *[支付环境下复杂的嵌套事务实例](../../wiki/支付环境下复杂的嵌套事务)
- 子查询subQuery
- [SubSql防注入From子查询](../../wiki/SubQuery安全子查询)
- [SubWhere防注入where子查询](../../wiki/SubWhere安全子查询)
- *[SubSql防注入From子查询](../../wiki/SubQuery安全子查询)
- *[SubWhere防注入where子查询](../../wiki/SubWhere安全子查询)
- 安全性能
- [Paginator-Performance-by-ChatGPT](../../wiki/Paginator分页查询的性能问题-ChatGPT )
- 单条/多条查询(Struct)
- *[Scan方法](../../wiki/Scan将结果独立输出到struct)

## 简介

Expand Down Expand Up @@ -165,16 +169,13 @@ panic(err.Error())
## TODO

- 加入缓存层
- 如果不使用Struct来接收返回,可能会导致Hash返回的Column类型从非string统一变成string(这是Redis的问题)
- 在开启缓存功能后避免使用断言是比较简单的解决方案,如果吧类型也存在Redis里面,固然能简单的解决但是也会增加Redis的链接负载
- 可选泛型返回
- 预计会对Select下手
- 或者新增Scan方法
- ScanGet\[T\]()
- ScanFind\[T\]()
- 如果不使用Struct来接收返回,可能会导致Hash返回的Column类型从非string统一变成string(这是Redis的问题)
- 在开启缓存功能后避免使用断言是比较简单的解决方案,如果吧类型也存在Redis里面,固然能简单的解决但是也会增加Redis的链接负载
- 可选泛型返回...已完成
- ElasticSearch
- 数据自动上载
- 从ES中读取数据
- 数据自动上载
- 从ES中读取数据

## Stargazers over time

[![Stargazers over time](https://starchart.cc/tobycroft/gorose-pro.svg)](https://starchart.cc/tobycroft/gorose-pro)
Expand Down
17 changes: 10 additions & 7 deletions README_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,27 +54,31 @@

## Docs and Demos(Wiki)

Notice:'*' means Only Support In GorosePro

- CUD functions
- [Insert](../../wiki/Insert新增数据)
- [Delete](../../wiki/Delete删除数据)
- [Update](../../wiki/Update方法)
- [Replace](../../wiki/Replace方法)
- *[Replace](../../wiki/Replace方法)
- Read the first line data and return in map[string]any
- [Find/First](../../wiki/Find-First查询返回Obj对象方法)
- Read multiple data in array by []map[string]any
- [Get/Select](../../wiki/Get-Select方法)
- [Join](../../wiki/Join-Select方法)
- [Paginator](../../wiki/Paginator复杂的子查询分页构建)
- [Paginator in HighPerformant](../../wiki/PaginatorWG多线程分页)
- *[Paginator](../../wiki/Paginator复杂的子查询分页构建)
- *[Paginator in HighPerformant](../../wiki/PaginatorWG多线程分页)
- Raw SQL sentence mode
- [Query](../../wiki/Query方法)
- Nested Transaction(only support in GorosePro)
- [Demos](../../wiki/支付环境下复杂的嵌套事务)
- *[Demos](../../wiki/支付环境下复杂的嵌套事务)
- subQuery
- [SubSql](../../wiki/SubQuery安全子查询)
- [SubWhere](../../wiki/SubWhere安全子查询)
- *[SubSql](../../wiki/SubQuery安全子查询)
- *[SubWhere](../../wiki/SubWhere安全子查询)
- Security and Performance
- [Paginator-Performance-by-ChatGPT](../../wiki/Paginator分页查询的性能问题-ChatGPT )
- Single/Multiple data to struct(Struct)
- *[Scan方法](../../wiki/Scan将结果独立输出到struct)

## Introduction

Expand Down Expand Up @@ -113,7 +117,6 @@ go get -u github.com/tobycroft/gorose-pro
- [MySQL initializing](../../wiki/初始化方法MySQL)
- [Oracle initializing](../../wiki/初始化方法Oracle)


For more configurations, you can configure the cluster, or even configure different databases at the same time. In a
cluster, the database will randomly select the database of the cluster to complete the corresponding read-write
operations. The master is the write database, and the slave is the read database. You need to do master-slave
Expand Down

0 comments on commit 5354b57

Please sign in to comment.