modulepackage
0.0.0-20210707103112-70f9aaf3947f
Repository: https://github.com/commonsun/gorm.git
Documentation: pkg.go.dev
# README
GORM
The fantastic ORM library for Golang, aims to be developer friendly.
Overview
- Full-Featured ORM (almost)
- Associations (Has One, Has Many, Belongs To, Many To Many, Polymorphism)
- Callbacks (Before/After Create/Save/Update/Delete/Find)
- Preloading (eager loading)
- Transactions
- Composite Primary Key
- SQL Builder
- Auto Migrations
- Logger
- Extendable, write Plugins based on GORM callbacks
- Every feature comes with tests
- Developer Friendly
Getting Started
- GORM Guides jinzhu.github.com/gorm
Upgrading To V1.0
Author
jinzhu
Contributors
https://github.com/CommonSun/gorm/graphs/contributors
License
Released under the MIT License.
# Packages
No description provided by the author
# Functions
Expr generate raw SQL expression, for example: DB.Model(&product).Update("price", gorm.Expr("price * ? + ?", 2, 100)).
Open initialize a new db connection, need to import driver first, e.g:
import _ "github.com/go-sql-driver/mysql" func main() { db, err := gorm.Open("mysql", "user:password@/dbname?charset=utf8&parseTime=True&loc=Local") } GORM has wrapped some drivers, for easier to remember driver's import path, so you could import the mysql driver with import _ "github.com/CommonSun/gorm/dialects/mysql" // import _ "github.com/CommonSun/gorm/dialects/postgres" // import _ "github.com/CommonSun/gorm/dialects/sqlite" // import _ "github.com/CommonSun/gorm/dialects/mssql".
ParseFieldStructForDialect parse field struct for dialect.
RegisterDialect register new dialect.
ToDBName convert string to db name.
# Variables
DefaultCallback default callbacks defined by gorm.
DefaultTableNameHandler default table name handler.
ErrCantStartTransaction can't start transaction when you are trying to start one with `Begin`.
ErrInvalidSQL invalid SQL error, happens when you passed invalid SQL.
ErrInvalidTransaction invalid transaction when you are trying to `Commit` or `Rollback`.
ErrRecordNotFound record not found error, happens when haven't find any matched data when looking up with a struct.
ErrUnaddressable unaddressable value.
NowFunc returns current time, this function is exported in order to be able to give the flexibility to the developer to customize it according to their needs, e.g: gorm.NowFunc = func() time.Time { return time.Now().UTC() }.
# Structs
Association Mode contains some helper methods to handle relationship things easily.
Callback is a struct that contains all CURD callbacks Field `creates` contains callbacks will be call when creating object Field `updates` contains callbacks will be call when updating object Field `deletes` contains callbacks will be call when deleting object Field `queries` contains callbacks will be call when querying object with query methods like Find, First, Related, Association..
CallbackProcessor contains callback informations.
DB contains information for current db connection.
DefaultForeignKeyNamer contains the default foreign key name generator method.
Errors contains all happened errors.
Field model field definition.
JoinTableForeignKey join table foreign key struct.
JoinTableHandler default join table handler.
JoinTableSource is a struct that contains model type and foreign keys.
Logger default logger.
Model base model definition, including fields `ID`, `CreatedAt`, `UpdatedAt`, `DeletedAt`, which could be embedded in your models type User struct { gorm.Model }.
ModelStruct model definition.
Relationship described the relationship between models.
Scope contain current operation's information when you perform any operation on the database.
StructField model field's struct definition.
# Interfaces
Dialect interface contains behaviors that differ across SQL database.
Instrumenter interface to help instrument queries.
JoinTableHandlerInterface is an interface for how to handle many2many relations.
LogWriter log writer interface.