Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/ablegao/orm

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/ablegao/orm

  • v0.0.0-20150310032514-4ec8d7d280bc
  • Source
  • Go
  • Socket score

Version published
Created
Source

##About

server-nado

一个数据库ORM.

Please go to http://github.com/server-nado/orm !

代码已经转移到 http://github.com/server-nado/orm !

How to use?

Insert

go get github.com/server-nado/orm

Super database

sqlite3 "github.com/mattn/go-sqlite3" mysql "github.com/go-sql-driver/mysql" postgree "github.com/lib/pq"

##数据库Model 建立方法

//引用模块
import "github.com/ablegao/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.Object
	Id int64 `field:"id" auto:"true" index:"pk"`
	Name string `field:"username"`
	Passwd string `field:"password"`
}

更多信息>>

##新增 CacheModel 模型, 支持分布式redis作为数据库缓存。

import "github.com/ablegao/orm"
import _ "github.com/go-sql-driver/mysql"

type userB struct {
	CacheModule
	Uid     int64  `field:"Id" index:"pk" cache:"user" `
	Alias   string `field:"Alias"`
	Money int64  `field:"money"	`
}

func main(){
	orm.CacheConsistent.Add("127.0.0.1:6379")  //添加多个redis服务器
	orm.SetCachePrefix("nado") //默认nado .  将作为redis key 的前缀
	NewDatabase("default", "mysql", "happy:passwd@tcp(127.0.0.1:3306)/mydatabase?charset=utf8&parseTime=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数据。 


}

FAQs

Package last updated on 10 Mar 2015

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc