Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding example usage #299

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Adding example usage
Signed-off-by: Yash Israni <[email protected]>
yashisrani committed Jan 18, 2025

Verified

This commit was signed with the committer’s verified signature.
chenchanglew Zac Lew
commit f8b2d9bd50f7c405b41015b88911e515e80d76b3
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -27,5 +27,34 @@ db, err := gorm.Open(postgres.New(postgres.Config{
}), &gorm.Config{})
```

## Example Usage

```go
import (
"fmt"

"gorm.io/driver/postgres"
"gorm.io/gorm"
)

type Postgress struct {
DB *gorm.DB
}

func (store *Postgress) NewStore() error {
dsn := "host=localhost user=gorm password=gorm dbname=gorm port=9920 sslmode=disable TimeZone=Asia/Shanghai"
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})

if err != nil {
fmt.Println("connection failed")
return err
}else{
fmt.Println("Database connected successfully")
store.DB = db
}

return nil
}
```

Checkout [https://gorm.io](https://gorm.io) for details.