
Research
Security News
The Landscape of Malicious Open Source Packages: 2025 Mid‑Year Threat Report
A look at the top trends in how threat actors are weaponizing open source packages to deliver malware and persist across the software supply chain.
github.com/server-nado/orm
##About
一个数据库ORM.
go get github.com/server-nado/orm
sqlite3 "github.com/mattn/go-sqlite3" mysql "github.com/go-sql-driver/mysql" postgree "github.com/lib/pq"
##数据库DBHook 建立方法
//引用模块
import "github.com/server-nado/orm"
//mysql 驱动
import _ "github.com/go-sql-driver/mysql"
//建立连接
// 参数分别为 名称 , 驱动, 连接字符串
// 注:必须包含一个default 连接, 作为默认连接。
orm.NewDatabase("default" , "mysql" , "user:passwd@ip/database?charset=utf8&parseTime=true")
//建立一个数据模型。
type UserInfo struct**** {
orm.DBHook
Id int64 `field:"id" auto:"true" index:"pk"`
Name string `field:"username"`
Passwd string `field:"password"`
}
//读写分离:
orm.NewDatabase("write-conname" , "mysql" , "user:passwd@tcp(ip:port)/database?charset=utf8&parseTime=true")
orm.NewDatabase("read-conname" , "mysql" , "user:passwd@tcp(ip:port)/database?charset=utf8&parseTime=true")
orm.SetWriteConnectName("write-conname")
orm.SetReadConnectName("read-conname")
//Cache (Redis)
orm.AddCacheAddress("127.0.0.1:6379","PASSWD") //缓存服务器地址
##新增 CacheHook 模型, 支持分布式redis作为数据库缓存。
import "github.com/server-nado/orm"
import _ "github.com/go-sql-driver/mysql"
type userB struct {
orm.CacheHook
Uid int64 `field:"Id" index:"pk" cache:"user" `
Alias string `field:"Alias"`
Money int64 `field:"money" `
}
func main(){
orm.AddCacheAddress("127.0.0.1:6379",PASSWD) //添加多个redis服务器
orm.SetCachePrefix("nado") //默认nado . 将作为redis key 的前缀
orm.NewDatabase("default", "mysql", "happy:passwd@tcp(127.0.0.1:3306)/mydatabase?charset=utf8&parseTime=true")
orm.SetCachePrefix("nado") //cache 前缀。
orm.SetDebug(false) //true 是否开启调试模式
b := new(userB)
b.Uid = 10000
err:=b.Objects(b).One()
if err!= nil {
panic(err)
}
fmt.Println(b.Uid ,b.Alias ,b.Money)
b.Incrby("Money" , 100)
fmt.Println(b.Money)
b.Save() //不执行不会保存到数据库 只会修改redis数据。
//查询id小于10的所有数据
user := new(userB)
users := []*userB{}
if err := user.Objects(user).Filter("Uid__lt",10).All(&users); err == nil{
for _,u:= range users{
fmt.Println(u.Uid , u.Alias)
}
}
}
##一些说明, 这个ORM的目的:
比较适合出现频繁,高性能要求的数据库读写操作。 使用CacheHook 模式操作数据时, 大多数情况下,热数据会被导入到缓存,这样的情况下, mysql的度频率会降低,读速度会提高很多,同时, 使用Set或者Incry等方式修改数据, 写速度会大大提升。
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A look at the top trends in how threat actors are weaponizing open source packages to deliver malware and persist across the software supply chain.
Security News
ESLint now supports HTML linting with 48 new rules, expanding its language plugin system to cover more of the modern web development stack.
Security News
CISA is discontinuing official RSS support for KEV and cybersecurity alerts, shifting updates to email and social media, disrupting automation workflows.