Discover Packages
github.com/ecodeclub/ekit
sqlx
package
Version:
v0.0.7
Opens a new window with list of versions in this module.
Published: Apr 13, 2023
License: Apache-2.0
Opens a new window with license information.
Imports: 10
Opens a new window with list of imports.
Imported by: 15 modules, 2 packages
The first number is the count of modules that contain a package that imports this one.
The module count is a better indicator of popularity than the package count.
A module with 100 importing packages is counted only once instead of 100 times,
reflecting the fact that the choice to use the package was likely made only once,
not 100 times.
A '?' means that the value hasn't been computed yet.
Opens a new window with list of known importers.
Documentation
Documentation
¶
EncryptColumn 代表一个加密的列
一般来说加密可以选择依赖于数据库进行加密
EncryptColumn 并不打算使用极其难破解的加密算法
而是选择使用 AES GCM 模式。
如果你觉得安全性不够,那么你可以考虑自己实现类似的结构体.
func (*EncryptColumn[T]) Scan ¶
Scan 方法会把写入的数据转化进行解密,
并将解密后的数据进行反序列化,构造 T
func (EncryptColumn[T]) Value ¶
Value 返回加密后的值
如果 T 是基本类型,那么会对 T 进行直接加密
否则,将 T 按照 JSON 序列化之后进行加密,返回加密后的数据
type JsonColumn[T any ] struct {
Val T
Valid bool
}
JsonColumn 代表存储字段的 json 类型
主要用于没有提供默认 json 类型的数据库
T 可以是结构体,也可以是切片或者 map
理论上来说一切可以被 json 库所处理的类型都能被用作 T
不建议使用指针作为 T 的类型
如果 T 是指针,那么在 Val 为 nil 的情况下,一定要把 Valid 设置为 false
func (*JsonColumn[T]) Scan ¶
Scan 将 src 转化为对象
src 的类型必须是 []byte, string 或者 nil
如果是 nil,我们不会做任何处理
js := JsonColumn[User]{}
err := js.Scan(`{"Name":"Tom"}`)
if err != nil {
fmt.Println(err)
}
fmt.Print(js.Val)
Output:
{Tom}
func (JsonColumn[T]) Value ¶
Value 返回一个 json 串。类型是 []byte
js := JsonColumn[User]{Valid: true, Val: User{Name: "Tom"}}
value, err := js.Value()
if err != nil {
fmt.Println(err)
}
fmt.Print(string(value.([]byte)))
Output:
{"Name":"Tom"}
Source Files
¶
Click to show internal directories.
Click to hide internal directories.