https://github.com/spacetab-io/i18n-postgre-go
https://github.com/spacetab-io/i18n-postgre-go
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/spacetab-io/i18n-postgre-go
- Owner: spacetab-io
- License: gpl-3.0
- Created: 2020-05-19T06:38:14.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-07-08T05:49:05.000Z (almost 5 years ago)
- Last Synced: 2025-02-14T22:13:51.902Z (3 months ago)
- Language: Go
- Size: 16.6 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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 packimport (
"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
}
```