An open API service indexing awesome lists of open source software.

https://github.com/spacetab-io/i18n-postgre-go


https://github.com/spacetab-io/i18n-postgre-go

Last synced: about 1 month ago
JSON representation

Awesome Lists containing this project

README

        

# i18n-postgre-go
Expending i18-go structures to bind them for PostgreSQL libs (gorm, lib/pq)

# Usage
## Translation

```go
package pack

import (
"database/sql"

"github.com/jinzhu/gorm"
"github.com/spacetab-io/i18n-go/translation"
translation_postgre "github.com/spacetab-io/i18n-postgre-go/translation"

)

// A model definition

type Record struct {
Id int `json:"id"`
Name translation.String `json:"name"`
}

type RecordGorm struct {
Id int `json:"id"`
Name translation_postgre.String `json:"name"`
}

func FetchRec(rows *sql.Result) (*Record, error) {
record := &Record{}

return record, rows.Scan(
&record.Id,
&translation_postgre.Bind{
V: &record.Name,
},
)
}

func Get(db *gorm.DB, id int) *RecordGorm {
record := &RecordGorm{}

db.First(record, id)

return record
}
```