gormDBPlus

package module
Version: v0.0.0-...-c85365b Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2021 License: MIT Imports: 1 Imported by: 0

README

gorm-db-builder

Türkçe Kullanım Örneği

Detaylı Kullanım örneklerini aşağıdaki makaleden inceleyebilirsiniz. https://alameddinc.medium.com/gorm-db-için-arayüz-geliştirmek-4df6fd641840

Örnek Kullanımlar (V1)

Connection İçin Örnek Fonksiyon

import (
	. "github.com/alameddinc/gorm-db-builder"
	"gorm.io/driver/postgres"
	"gorm.io/gorm"
)

func Connection() *Connector{
	dsn := "host=127.0.0.1 user=username password=password DB.name=database port=5432 sslmode=disable"
	db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
	if err != nil {
		panic(err)
	}
	return &Connector{RawConnection: db}
}

Kütüphane Fonksiyonının Örnek Kullanımları

FetchOne

func (p *Class) FetchOne(with ...string) error {  
   return DB.FetchOne(p, nil, with...)  
}

FetchAll

type Cities []City  
  
func (p *Cities) FetchAll(where *City, with ...string) error {  
   if where == nil {  
      where = &City{}  
   }  
   return DB.FetchAll(p, where, nil, with...)  
}

Update

func (p *City) Update(update *City) error {  
   return DB.Update(p, update, nil)  
}

//Bulk Update
type Cities []City 

func (p *Cities) UpdateBulk(update *City) error {  
   return DB.Update(p, update, nil)  
}

Save

func (p *City) Save() error {  
   err := DB.Save(p)  
   if err != nil {  
      return err  
   }  
   return p.FetchOne()  
}

// Bulk Save
type Cities []City  
  
func (p *Cities) SaveBulk() error {  
   err := DB.Save(p)  
   if err != nil {  
      return err  
   }  
   return p.FetchOne()  
}

FetchAll


type Cities []City  
func (p *Cities) DeleteBulk() error {  
   return DB.Remove(p, nil)  
}

Remove

func (p *City) Delete() error {  
   return DB.Remove(p, nil)  
}

//Bulk Remove
type Cities []City  
  
func (p *Cities) FetchAll(where *City, with ...string) error {  
   return DB.Remove(p, nil)  
}

FetchOneWithId

func (p *City) FetchOneWithId(id int, with ...string) error {  
   return DB.FetchOneWithID(p, id, nil, with...) 
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConnectionConfig

type ConnectionConfig struct {
	User     string
	Password string
	Host     string
	Port     int
	DB       string
	SSL      bool
}

type Connector

type Connector struct {
	RawConnection *gorm.DB
}

func NewConnectorWithDB

func NewConnectorWithDB(db *gorm.DB) *Connector

func (*Connector) AppendChild

func (c *Connector) AppendChild(p interface{}, typeName string, child interface{}, tx *gorm.DB) error

func (*Connector) ClearChild

func (c *Connector) ClearChild(p interface{}, typeName string, tx *gorm.DB) error

func (*Connector) CountChild

func (c *Connector) CountChild(p interface{}, typeName string, tx *gorm.DB) int64

func (*Connector) FetchAll

func (c *Connector) FetchAll(dest interface{}, condition interface{}, tx *gorm.DB, with ...string) error

func (*Connector) FetchOne

func (c *Connector) FetchOne(dest interface{}, tx *gorm.DB, with ...string) error

func (*Connector) FetchOneWithID

func (c *Connector) FetchOneWithID(dest interface{}, id int, tx *gorm.DB, with ...string) error

func (*Connector) IsExist

func (c *Connector) IsExist(p interface{}, tx *gorm.DB) (bool, error)

func (*Connector) NewTransaction

func (c *Connector) NewTransaction() *gorm.DB

func (*Connector) Remove

func (c *Connector) Remove(p interface{}, tx *gorm.DB) error

func (*Connector) ReplaceChild

func (c *Connector) ReplaceChild(p interface{}, typeName string, child interface{}, tx *gorm.DB) error

func (*Connector) Save

func (c *Connector) Save(p interface{}, tx *gorm.DB) error

func (*Connector) Update

func (c *Connector) Update(p interface{}, update interface{}, tx *gorm.DB) error

Source Files

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL