Skip to content

🔑 Go shortuuid library with `database/sql` support.

License

Notifications You must be signed in to change notification settings

blackieops/primarykey

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go.b8s.dev/primarykey

Test Suite Go Report Card

The goal with primarykey is to provide a bridge between github.com/google/uuid and github.com/lithammer/shortuuid while also supporting database interfaces so they can continue to be used as column types in things like gorm.io/gorm.

Usage

The primarykey.ID type is byte-compatible with UUIDs, and provides all the interfaces required to be used as a database column type. For example, if you have a gorm model:

import "go.b8s.dev/primarykey"

type MyModel struct {
	ID primarykey.ID
}

There is also a public interface to encode and decode directly:

newOne := primarykey.New()
Encode(newOne) //=> "KwSysDpxcBU9FNhGkn2dCf"

id := Decode("KwSysDpxcBU9FNhGkn2dCf") //=> ID
id.UUID() //=> uuid.UUID
id.String() //=> "KwSysDpxcBU9FNhGkn2dCf"

Development

This is a very standard Go project with very minimal dependencies and no required setup. Dependencies are vendored.

To run the test suite,

$ go test .

That's about it.