Skip to content

spacetab-io/i18n-postgre-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

i18n-postgre-go

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

Usage

Translation

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
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages