dbutil

package module
v0.0.0-...-49d60cc Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2019 License: MIT Imports: 7 Imported by: 0

README

dbutil

This is experimental for make my life easier, without dependend to any ORM/driver besides what that provide by go.

Right now, it only support Postgres (because of different syntax between SQL)

Database Synchronization

Put this script into file like sync.go

package main

import (
	"database/sql"
	_ "github.com/lib/pq"
	"log"

	"yourdomain"
	"github.com/egon12/dbutil"
)

func main() {

	db, err := sql.Open("postgres", "user=user dbname=db_to_sync password=password sslmode=disable")
	defer db.Close()

	if err != nil {
		log.Fatal(err)
	}
	dbutil.Db = db

	emptyEntity := yourdomain.Entity{}
	dbutil.InteractiveSync(emptyEntity)
}

and then execute

go run sync.go

Repository Generator

Put this script into file like generate.go

package main

import (
	"yourdomain"
	"github.com/egon12/dbutil"
	"log"
)

func main() {

	emptyEntity := yourdomain.Entity{}
	err := dbutil.GenerateRepository("gateway", emptyEntity, "./gateway/repository.go")
	if err != nil {
		log.Fatal(err)
	}
}

and then execute

go run generate.go

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MockDb = &mock.MockDbDriver{}
)

Functions

func GenerateRepository

func GenerateRepository(packageName string, realEntity interface{}, filename string) error

func ToSnakeCase

func ToSnakeCase(str string) string

ToSnakeCase make camelCase into camel_case or nameWithSnakeCase into name_with_snake_case

Types

type IRepoGenerator

type IRepoGenerator interface {
	Generate()
	GoString()
	Save(string)
}

type RepoGenerator

type RepoGenerator struct {
	// contains filtered or unexported fields
}

func NewRepoGenerator

func NewRepoGenerator(
	packageName string,
	realEntity interface{},
	fieldFilterFunc func(reflect.StructField) bool,
) (*RepoGenerator, error)

func (*RepoGenerator) Generate

func (repoGenerator *RepoGenerator) Generate()

func (*RepoGenerator) GoString

func (repoGenerator *RepoGenerator) GoString() string

func (*RepoGenerator) Save

func (repoGenerator *RepoGenerator) Save(filename string) error

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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