i18n-go-postgre

module
v0.0.0-...-6a69ebc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 19, 2020 License: GPL-3.0

README

This package moved to https://github.com/spacetab-io/i18n-postgre-go

i18n-go-postgre

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/microparts/i18n-go/translation"
	translation_postgre "github.com/microparts/i18n-go-postgre/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
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL