Giter Site home page Giter Site logo

wuid's People

Contributors

dependabot[bot] avatar dwin avatar edwingeng avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wuid's Issues

调用wuid生成id后,会自动关闭数据库连接,导致后续数据库操作无法继续执行

调用wuid生成id后,会自动关闭数据库连接,导致后续数据库操作无法继续执行
package tools
import (

"database/sql"
"github.com/astaxie/beego/orm"
"github.com/edwingeng/wuid/mysql"
_"github.com/go-sql-driver/mysql"

)

var newDB = func() (*sql.DB,bool,error){
db,_ := orm.GetDB()
return db,true,nil
}

var g = wuid.NewWUID("default", nil)

func NewId() (uint64){
g.LoadH28FromMysql(newDB, "wuid")
return g.Next()
}

调用代码:

func AddUser(u *User) (int64, error) {
// db,err := orm.GetDB()
//fmt.Println(err)
o := orm.NewOrm()
u.Id = 74837477878
for i:=0;i<100;i++ {
fmt.Println(tools.NewId())
}

fmt.Println(u)
return o.Insert(u)

}

插入操作无法继续执行,
[ORM]2019/05/12 22:09:56 -[Queries/default] - [FAIL / db.Exec / 0.0ms] - [INSERT INTO sys_user (id, username, password, phone, email, name, avatar, salt, status, is_staff, last_login_time, login_error_times, remark, delete_flag, create_by, create_time, update_by, update_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)] - 74837477878, qingmumao,
xxxxxxxx, 13332978703, [email protected], , , , `0`, `0`, `0`, `0`, , 0, 0, 0, 0, 0 - sql: database is closed

请问wuid生成的id拿来做主键合适吗

假如用wuid来表示一个订单的ID, 存储到数据里里面推荐用它的字符串表示还是直接用数字呢?
如果存储的是数字, wuid返回uint64类型, 拿来做主键合适吗?

Document expected behaviour of floor

The behaviour of how the floor impacts the output isn't really documented and the term itself brings confusion.

From https://en.wikipedia.org/wiki/Floor_and_ceiling_functions :

In mathematics and computer science, the floor function is the function that takes as input a real number x, and gives as output the greatest integer less than or equal to x.

Based on this definition, when I specified a step of 1024 with a floor of 897 and H28 of 1 I didn't expect to receive a value of 0x00000010000003a7 followed by 0x0000001000000728 and 0x0000001000000aa9; given that 0xAA9 is much higher than the "floor" value. It's obvious why this is happening when looking at the code where next() returns n / floor * floor.

The best that I can see is this is somehow useful in order to make it less obvious what the "step" actually is, using a Real number as step and benefiting from rounding to nearest Integer, causing the steps to be +/- 1. A floor > 1 is also a requirement when used with obfuscation to hide the obfuscation values used.

However the main issue is that I couldn't find any documentation about this expected behaviour, so as a user of this library I ended up having to dig through the code to figure it out.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.