Skip to content
This repository has been archived by the owner on Aug 29, 2021. It is now read-only.
/ gorm-default-value Public archive

A demo detects the gorm behavior with database default value

License

Notifications You must be signed in to change notification settings

junhuif/gorm-default-value

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gorm Default Value

Gorm takes the default value back from database after you create a new record with no value specified.

Quick Started

# Get code
$ go get -u github.com/fengjh/gorm-default-value

# Set environment variables
$ source .env

# Setup postgres database
$ postgres=# CREATE USER gorm_default_value;
$ postgres=# CREATE DATABASE gorm_default_value OWNER gorm_default_value;

# Run Application
$ go test -v

Test Result

=== RUN   TestCreateProductWithNoValueSpecified
BeforeCreate --> 0
BeforeCreate -->
AfterCreate --> 0.01
AfterCreate --> clothing
BeforeCreateTransactionCommit --> 0.01
BeforeCreateTransactionCommit --> clothing
AfterCreateTransactionCommit --> 0.01
AfterCreateTransactionCommit --> clothing
--- PASS: TestCreateProductWithNoValueSpecified (0.00s)
=== RUN   TestSaveProductPriceWithNoValueSpecified
BeforeCreate --> 0
BeforeCreate -->
AfterCreate --> 0.01
AfterCreate --> clothing
BeforeCreateTransactionCommit --> 0.01
BeforeCreateTransactionCommit --> clothing
AfterCreateTransactionCommit --> 0.01
AfterCreateTransactionCommit --> clothing
--- PASS: TestSaveProductPriceWithNoValueSpecified (0.00s)
=== RUN   TestCreateProductPriceWithZeroValueSpecified
BeforeCreate --> 0
BeforeCreate -->
AfterCreate --> 0.01
AfterCreate --> clothing
BeforeCreateTransactionCommit --> 0.01
BeforeCreateTransactionCommit --> clothing
AfterCreateTransactionCommit --> 0.01
AfterCreateTransactionCommit --> clothing
--- PASS: TestCreateProductPriceWithZeroValueSpecified (0.00s)
PASS
ok  	github.com/fengjh/gorm-default-value	0.075s

About

A demo detects the gorm behavior with database default value

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages