Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Commit

Permalink
Merge pull request #59 from qor5/change-example-db
Browse files Browse the repository at this point in the history
change example db from SQLite to PosgreSQL
  • Loading branch information
iBakuman authored Oct 13, 2023
2 parents dee9e2a + 49c6668 commit ea0f6b7
Show file tree
Hide file tree
Showing 14 changed files with 82 additions and 21 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ To run the QOR5 documentation locally, follow these steps:

1. Clone this repository to your local machine.
2. Navigate to the `docsrc` directory.
3. Execute the `dev.sh` script.
4. Access the documentation in your web browser at http://localhost:8800 to view the documentation.
3. Run `docker-compose up`.
4. Execute the `dev.sh` script.
5. Access the documentation in your web browser at http://localhost:8800 to view the documentation.
2 changes: 1 addition & 1 deletion docs/activity-log.html
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ <h2><a name="initialize-the-activity-package" class="anchor" href="#initialize-t

<p>To initialize activity package with the default configuration, you need to pass a <code>presets.Builder</code> instance and a database instance.</p>

<highlightjs :language='"go"' :code='"presetsBuilder := presets.New()\ndb, err := gorm.Open(sqlite.Open(\"/tmp/activity.db\"), \u0026gorm.Config{})\nif err != nil {\n\tpanic(err)\n}\nactivityBuilder := activity.New(presetsBuilder, db)"'></highlightjs>
<highlightjs :language='"go"' :code='"presetsBuilder := presets.New()\ndb, err := gorm.Open(postgres.Open(os.Getenv(\"DB_PARAMS\")), \u0026gorm.Config{})\nif err != nil {\n\tpanic(err)\n}\nactivityBuilder := activity.New(presetsBuilder, db)"'></highlightjs>
<p>By default, the activity package uses QOR5 login package&#39;s <code>login.UserKey</code> as the default key to fetch the current user from the context. If you want to use your own key, you can use the <code>SetCreatorContextKey</code> function.</p>

<p>Same with above, the activity package uses the db instance that passed in during initialization to perform db operations. If you need another db to do the work, you can use <code>SetDBContextKey</code> method.</p>
Expand Down
2 changes: 1 addition & 1 deletion docs/presets-guide/its-the-whole-house.html
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ <h1 class='mb-8'>Not just scaffolding, it&#39;s the whole house</h1>
It&#39;s not a scaffolding to generate source code. But provide more abstract and
flexible API to enrich features along the way.</p>

<highlightjs :language='"go"' :code='"package e21_presents\n\nimport (\n\t\"fmt\"\n\t\"net/url\"\n\t\"time\"\n\n\t\"github.com/qor5/admin/presets\"\n\t\"github.com/qor5/admin/presets/actions\"\n\t\"github.com/qor5/admin/presets/gorm2op\"\n\tv \"github.com/qor5/ui/vuetify\"\n\t\"github.com/qor5/ui/vuetifyx\"\n\t\"github.com/qor5/web\"\n\t\"github.com/qor5/x/i18n\"\n\th \"github.com/theplant/htmlgo\"\n\t\"golang.org/x/text/language\"\n\t\"gorm.io/driver/sqlite\"\n\t\"gorm.io/gorm\"\n\t\"gorm.io/gorm/logger\"\n)\n\ntype Customer struct {\n\tID int\n\tName string\n\tEmail string\n\tDescription string\n\tCompanyID int\n\tCreatedAt time.Time\n\tUpdatedAt time.Time\n\tApprovedAt *time.Time\n\tTermAgreedAt *time.Time\n\tApprovalComment string\n}\n\ntype Address struct {\n\tID int\n\tProvince string\n\tCity string\n\tDistrict string\n}\n\nvar DB *gorm.DB\n\nfunc init() {\n\tDB = setupDB()\n}\n\nfunc setupDB() (db *gorm.DB) {\n\tvar err error\n\tdb, err = gorm.Open(sqlite.Open(\"/tmp/my.db\"), \u0026gorm.Config{})\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tdb.Logger.LogMode(logger.Info)\n\terr = db.AutoMigrate(\n\t\t\u0026Customer{},\n\t\t\u0026Company{},\n\t\t\u0026Address{},\n\t)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\treturn\n}\n\nfunc PresetsHelloWorld(b *presets.Builder) (m *presets.ModelBuilder, db *gorm.DB) {\n\tdb = DB\n\n\tb.I18n().\n\t\tSupportLanguages(language.English, language.SimplifiedChinese).\n\t\tRegisterForModule(language.SimplifiedChinese, presets.ModelsI18nModuleKey, Messages_zh_CN)\n\n\tb.URIPrefix(PresetsHelloWorldPath).\n\t\tDataOperator(gorm2op.DataOperator(db))\n\tm = b.Model(\u0026Customer{})\n\n\treturn\n}\n\nconst PresetsHelloWorldPath = \"/samples/presets-hello-world\"\n"'></highlightjs>
<highlightjs :language='"go"' :code='"package e21_presents\n\nimport (\n\t\"fmt\"\n\t\"net/url\"\n\t\"os\"\n\t\"time\"\n\n\t\"github.com/qor5/admin/presets\"\n\t\"github.com/qor5/admin/presets/actions\"\n\t\"github.com/qor5/admin/presets/gorm2op\"\n\tv \"github.com/qor5/ui/vuetify\"\n\t\"github.com/qor5/ui/vuetifyx\"\n\t\"github.com/qor5/web\"\n\t\"github.com/qor5/x/i18n\"\n\th \"github.com/theplant/htmlgo\"\n\t\"golang.org/x/text/language\"\n\t\"gorm.io/driver/postgres\"\n\t\"gorm.io/gorm\"\n\t\"gorm.io/gorm/logger\"\n)\n\ntype Customer struct {\n\tID int\n\tName string\n\tEmail string\n\tDescription string\n\tCompanyID int\n\tCreatedAt time.Time\n\tUpdatedAt time.Time\n\tApprovedAt *time.Time\n\tTermAgreedAt *time.Time\n\tApprovalComment string\n}\n\ntype Address struct {\n\tID int\n\tProvince string\n\tCity string\n\tDistrict string\n}\n\nvar DB *gorm.DB\n\nfunc init() {\n\tDB = setupDB()\n}\n\nfunc setupDB() (db *gorm.DB) {\n\tvar err error\n\tdb, err = gorm.Open(postgres.Open(os.Getenv(\"DB_PARAMS\")), \u0026gorm.Config{})\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tdb.Logger.LogMode(logger.Info)\n\terr = db.AutoMigrate(\n\t\t\u0026Customer{},\n\t\t\u0026Company{},\n\t\t\u0026Address{},\n\t)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\treturn\n}\n\nfunc PresetsHelloWorld(b *presets.Builder) (m *presets.ModelBuilder, db *gorm.DB) {\n\tdb = DB\n\n\tb.I18n().\n\t\tSupportLanguages(language.English, language.SimplifiedChinese).\n\t\tRegisterForModule(language.SimplifiedChinese, presets.ModelsI18nModuleKey, Messages_zh_CN)\n\n\tb.URIPrefix(PresetsHelloWorldPath).\n\t\tDataOperator(gorm2op.DataOperator(db))\n\tm = b.Model(\u0026Customer{})\n\n\treturn\n}\n\nconst PresetsHelloWorldPath = \"/samples/presets-hello-world\"\n"'></highlightjs>
<p>And this <code>*presets.Builder</code> instance is actually also a <code>http.Handler</code>, So that we can mount it
to the http serve mux directly like this:</p>

Expand Down
2 changes: 1 addition & 1 deletion docs/search_indexes.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/vuetify-components/auto-complete.html
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ <h1 class='mb-8'>Auto Complete</h1>
<li>A static normal select component</li>
</ul>

<highlightjs :language='"go"' :code='"\nimport (\n\t\"fmt\"\n\n\t\"github.com/qor5/admin/presets\"\n\t\"github.com/qor5/admin/presets/gorm2op\"\n\t. \"github.com/qor5/ui/vuetify\"\n\t\"github.com/qor5/ui/vuetifyx\"\n\t\"github.com/qor5/web\"\n\th \"github.com/theplant/htmlgo\"\n\t\"gorm.io/driver/sqlite\"\n\t\"gorm.io/gorm\"\n)\n\ntype (\n\tUser struct {\n\t\tLogin string\n\t\tName string\n\t}\n\n\tUserIcons struct {\n\t\tLogin string `json:\"text\"`\n\t\tName string `json:\"value\"`\n\t\tIcon string `json:\"icon\"`\n\t}\n\n\tProduct struct {\n\t\tID uint `gorm:\"primarykey\"`\n\t\tName string\n\t}\n)\n\nvar (\n\toptions = []*User{\n\t\t{Login: \"sam\", Name: \"Sam\"},\n\t\t{Login: \"john\", Name: \"John\"},\n\t\t{Login: \"charles\", Name: \"Charles\"},\n\t}\n\n\ticonOptions = []*UserIcons{\n\t\t{Login: \"sam\", Name: \"Sam\", Icon: \"https://cdn.vuetifyjs.com/images/lists/1.jpg\"},\n\t\t{Login: \"john\", Name: \"John\", Icon: \"https://cdn.vuetifyjs.com/images/lists/2.jpg\"},\n\t\t{Login: \"charles\", Name: \"Charles\", Icon: \"https://cdn.vuetifyjs.com/images/lists/3.jpg\"},\n\t}\n\n\tloadMoreRes *vuetifyx.AutocompleteDataSource\n\tpagingRes *vuetifyx.AutocompleteDataSource\n\tExamplePreset *presets.Builder\n)\n\nfunc init() {\n\tdb, err := gorm.Open(sqlite.Open(\"/tmp/my.db\"), \u0026gorm.Config{})\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tdb.AutoMigrate(\u0026Product{})\n\tdb.Where(\"1=1\").Delete(\u0026Product{})\n\n\tfor i := 1; i \u003c 300; i++ {\n\t\tdb.Create(\u0026Product{Name: fmt.Sprintf(\"Product %d\", i)})\n\t}\n\n\tExamplePreset = presets.New()\n\tExamplePreset.URIPrefix(VuetifyAutoCompletePresetPath).DataOperator(gorm2op.DataOperator(db))\n\tlisting := ExamplePreset.Model(\u0026Product{}).Listing()\n\tloadMoreRes = listing.ConfigureAutocompleteDataSource(\n\t\t\u0026presets.AutocompleteDataSourceConfig{\n\t\t\tOptionValue: \"ID\",\n\t\t\tOptionText: \"Name\",\n\t\t\tOptionIcon: func(product interface{}) string {\n\t\t\t\treturn fmt.Sprintf(\"https://cdn.vuetifyjs.com/images/lists/%d.jpg\", product.(*Product).ID%4+1)\n\t\t\t},\n\t\t\tKeywordColumns: []string{\n\t\t\t\t\"Name\",\n\t\t\t},\n\t\t\tPerPage: 50,\n\t\t},\n\t\t\"loadMore\",\n\t)\n\n\tpagingRes = listing.ConfigureAutocompleteDataSource(\n\t\t\u0026presets.AutocompleteDataSourceConfig{\n\t\t\tOptionValue: \"ID\",\n\t\t\tOptionText: \"Name\",\n\t\t\tOptionIcon: func(product interface{}) string {\n\t\t\t\treturn fmt.Sprintf(\"https://cdn.vuetifyjs.com/images/lists/%d.jpg\", product.(*Product).ID%4+1)\n\t\t\t},\n\t\t\tKeywordColumns: []string{\n\t\t\t\t\"Name\",\n\t\t\t},\n\t\t\tPerPage: 20,\n\t\t\tIsPaging: true,\n\t\t\tOrderBy: \"Name\",\n\t\t},\n\t\t\"paging\",\n\t)\n\n}\n\nfunc VuetifyAutocomplete(ctx *web.EventContext) (pr web.PageResponse, err error) {\n\tpr.Body = VContainer(\n\t\th.H1(\"Select many (default)\"),\n\t\tvuetifyx.VXAutocomplete().\n\t\t\tLabel(\"Load options from a list\").\n\t\t\tItems(options).\n\t\t\tFieldName(\"Values1\").\n\t\t\tItemText(\"Name\").\n\t\t\tItemValue(\"Login\"),\n\n\t\th.H1(\"Select one\"),\n\t\tvuetifyx.VXAutocomplete().\n\t\t\tFieldName(\"Values2\").\n\t\t\tLabel(\"Load options from a list\").\n\t\t\tItems(options).\n\t\t\tItemText(\"Name\").\n\t\t\tItemValue(\"Login\").\n\t\t\tMultiple(false),\n\n\t\th.H1(\"Has icon\"),\n\t\tvuetifyx.VXAutocomplete().\n\t\t\tLabel(\"Load options from a list\").\n\t\t\tItems(iconOptions).\n\t\t\tHasIcon(true),\n\n\t\th.H1(\"Load more from remote resource\"),\n\t\tvuetifyx.VXAutocomplete().\n\t\t\tFieldName(\"Values2\").\n\t\t\tLabel(\"Load options from data source\").\n\t\t\tSetDataSource(loadMoreRes),\n\n\t\th.H1(\"Paging with remote resource\"),\n\t\tvuetifyx.VXAutocomplete().\n\t\t\tFieldName(\"Values2\").\n\t\t\tLabel(\"Load options from data source\").\n\t\t\tSetDataSource(pagingRes),\n\n\t\th.H1(\"Sorting\"),\n\t\tvuetifyx.VXAutocomplete().\n\t\t\tFieldName(\"Values2\").\n\t\t\tLabel(\"Load options from data source\").\n\t\t\tSorting(true).\n\t\t\tSetDataSource(pagingRes).ChipColor(\"red\"),\n\t)\n\treturn\n}\n\nvar VuetifyAutocompletePB = web.Page(VuetifyAutocomplete)\n\nconst VuetifyAutoCompletePath = \"/samples/vuetify-auto-complete\"\nconst VuetifyAutoCompletePresetPath = \"/samples/vuetify-auto-complete-preset\"\n"'></highlightjs>
<highlightjs :language='"go"' :code='"\nimport (\n\t\"fmt\"\n\t\"os\"\n\n\t\"github.com/qor5/admin/presets\"\n\t\"github.com/qor5/admin/presets/gorm2op\"\n\t. \"github.com/qor5/ui/vuetify\"\n\t\"github.com/qor5/ui/vuetifyx\"\n\t\"github.com/qor5/web\"\n\th \"github.com/theplant/htmlgo\"\n\t\"gorm.io/driver/postgres\"\n\t\"gorm.io/gorm\"\n)\n\ntype (\n\tUser struct {\n\t\tLogin string\n\t\tName string\n\t}\n\n\tUserIcons struct {\n\t\tLogin string `json:\"text\"`\n\t\tName string `json:\"value\"`\n\t\tIcon string `json:\"icon\"`\n\t}\n\n\tProduct struct {\n\t\tID uint `gorm:\"primarykey\"`\n\t\tName string\n\t}\n)\n\nvar (\n\toptions = []*User{\n\t\t{Login: \"sam\", Name: \"Sam\"},\n\t\t{Login: \"john\", Name: \"John\"},\n\t\t{Login: \"charles\", Name: \"Charles\"},\n\t}\n\n\ticonOptions = []*UserIcons{\n\t\t{Login: \"sam\", Name: \"Sam\", Icon: \"https://cdn.vuetifyjs.com/images/lists/1.jpg\"},\n\t\t{Login: \"john\", Name: \"John\", Icon: \"https://cdn.vuetifyjs.com/images/lists/2.jpg\"},\n\t\t{Login: \"charles\", Name: \"Charles\", Icon: \"https://cdn.vuetifyjs.com/images/lists/3.jpg\"},\n\t}\n\n\tloadMoreRes *vuetifyx.AutocompleteDataSource\n\tpagingRes *vuetifyx.AutocompleteDataSource\n\tExamplePreset *presets.Builder\n)\n\nfunc init() {\n\tdb, err := gorm.Open(postgres.Open(os.Getenv(\"DB_PARAMS\")), \u0026gorm.Config{})\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tdb.AutoMigrate(\u0026Product{})\n\tdb.Where(\"1=1\").Delete(\u0026Product{})\n\n\tfor i := 1; i \u003c 300; i++ {\n\t\tdb.Create(\u0026Product{Name: fmt.Sprintf(\"Product %d\", i)})\n\t}\n\n\tExamplePreset = presets.New()\n\tExamplePreset.URIPrefix(VuetifyAutoCompletePresetPath).DataOperator(gorm2op.DataOperator(db))\n\tlisting := ExamplePreset.Model(\u0026Product{}).Listing()\n\tloadMoreRes = listing.ConfigureAutocompleteDataSource(\n\t\t\u0026presets.AutocompleteDataSourceConfig{\n\t\t\tOptionValue: \"ID\",\n\t\t\tOptionText: \"Name\",\n\t\t\tOptionIcon: func(product interface{}) string {\n\t\t\t\treturn fmt.Sprintf(\"https://cdn.vuetifyjs.com/images/lists/%d.jpg\", product.(*Product).ID%4+1)\n\t\t\t},\n\t\t\tKeywordColumns: []string{\n\t\t\t\t\"Name\",\n\t\t\t},\n\t\t\tPerPage: 50,\n\t\t},\n\t\t\"loadMore\",\n\t)\n\n\tpagingRes = listing.ConfigureAutocompleteDataSource(\n\t\t\u0026presets.AutocompleteDataSourceConfig{\n\t\t\tOptionValue: \"ID\",\n\t\t\tOptionText: \"Name\",\n\t\t\tOptionIcon: func(product interface{}) string {\n\t\t\t\treturn fmt.Sprintf(\"https://cdn.vuetifyjs.com/images/lists/%d.jpg\", product.(*Product).ID%4+1)\n\t\t\t},\n\t\t\tKeywordColumns: []string{\n\t\t\t\t\"Name\",\n\t\t\t},\n\t\t\tPerPage: 20,\n\t\t\tIsPaging: true,\n\t\t\tOrderBy: \"Name\",\n\t\t},\n\t\t\"paging\",\n\t)\n\n}\n\nfunc VuetifyAutocomplete(ctx *web.EventContext) (pr web.PageResponse, err error) {\n\tpr.Body = VContainer(\n\t\th.H1(\"Select many (default)\"),\n\t\tvuetifyx.VXAutocomplete().\n\t\t\tLabel(\"Load options from a list\").\n\t\t\tItems(options).\n\t\t\tFieldName(\"Values1\").\n\t\t\tItemText(\"Name\").\n\t\t\tItemValue(\"Login\"),\n\n\t\th.H1(\"Select one\"),\n\t\tvuetifyx.VXAutocomplete().\n\t\t\tFieldName(\"Values2\").\n\t\t\tLabel(\"Load options from a list\").\n\t\t\tItems(options).\n\t\t\tItemText(\"Name\").\n\t\t\tItemValue(\"Login\").\n\t\t\tMultiple(false),\n\n\t\th.H1(\"Has icon\"),\n\t\tvuetifyx.VXAutocomplete().\n\t\t\tLabel(\"Load options from a list\").\n\t\t\tItems(iconOptions).\n\t\t\tHasIcon(true),\n\n\t\th.H1(\"Load more from remote resource\"),\n\t\tvuetifyx.VXAutocomplete().\n\t\t\tFieldName(\"Values2\").\n\t\t\tLabel(\"Load options from data source\").\n\t\t\tSetDataSource(loadMoreRes),\n\n\t\th.H1(\"Paging with remote resource\"),\n\t\tvuetifyx.VXAutocomplete().\n\t\t\tFieldName(\"Values2\").\n\t\t\tLabel(\"Load options from data source\").\n\t\t\tSetDataSource(pagingRes),\n\n\t\th.H1(\"Sorting\"),\n\t\tvuetifyx.VXAutocomplete().\n\t\t\tFieldName(\"Values2\").\n\t\t\tLabel(\"Load options from data source\").\n\t\t\tSorting(true).\n\t\t\tSetDataSource(pagingRes).ChipColor(\"red\"),\n\t)\n\treturn\n}\n\nvar VuetifyAutocompletePB = web.Page(VuetifyAutocomplete)\n\nconst VuetifyAutoCompletePath = \"/samples/vuetify-auto-complete\"\nconst VuetifyAutoCompletePresetPath = \"/samples/vuetify-auto-complete-preset\"\n"'></highlightjs>

<div>
<div class='demo'>
Expand Down
2 changes: 2 additions & 0 deletions docsrc/dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ do
gi=$((gi+1))
done

export DB_PARAMS="user=docs password=docs dbname=docs sslmode=disable host=localhost port=6532 TimeZone=Asia/Tokyo"
export ENV="development"
go run ./build/main.go

function docsRestart() {
Expand Down
11 changes: 11 additions & 0 deletions docsrc/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: "3"

services:
db:
image: postgres
environment:
- "POSTGRES_USER=docs"
- "POSTGRES_PASSWORD=docs"
- "POSTGRES_DB=docs"
ports:
- 6532:5432
5 changes: 3 additions & 2 deletions docsrc/examples/e00_basics/activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ package e00_basics

import (
"context"
"os"

"github.com/qor5/admin/activity"
"github.com/qor5/admin/presets"
"gorm.io/driver/sqlite"
"gorm.io/driver/postgres"
"gorm.io/gorm"
)

func NewActivitySample() {
// @snippet_begin(NewActivitySample)
presetsBuilder := presets.New()
db, err := gorm.Open(sqlite.Open("/tmp/activity.db"), &gorm.Config{})
db, err := gorm.Open(postgres.Open(os.Getenv("DB_PARAMS")), &gorm.Config{})
if err != nil {
panic(err)
}
Expand Down
5 changes: 3 additions & 2 deletions docsrc/examples/e10_vuetify_autocomplete/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ package e10_vuetify_autocomplete

import (
"fmt"
"os"

"github.com/qor5/admin/presets"
"github.com/qor5/admin/presets/gorm2op"
. "github.com/qor5/ui/vuetify"
"github.com/qor5/ui/vuetifyx"
"github.com/qor5/web"
h "github.com/theplant/htmlgo"
"gorm.io/driver/sqlite"
"gorm.io/driver/postgres"
"gorm.io/gorm"
)

Expand Down Expand Up @@ -52,7 +53,7 @@ var (
)

func init() {
db, err := gorm.Open(sqlite.Open("/tmp/my.db"), &gorm.Config{})
db, err := gorm.Open(postgres.Open(os.Getenv("DB_PARAMS")), &gorm.Config{})
if err != nil {
panic(err)
}
Expand Down
5 changes: 3 additions & 2 deletions docsrc/examples/e21_presents/listing.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package e21_presents
import (
"fmt"
"net/url"
"os"
"time"

"github.com/qor5/admin/presets"
Expand All @@ -15,7 +16,7 @@ import (
"github.com/qor5/x/i18n"
h "github.com/theplant/htmlgo"
"golang.org/x/text/language"
"gorm.io/driver/sqlite"
"gorm.io/driver/postgres"
"gorm.io/gorm"
"gorm.io/gorm/logger"
)
Expand Down Expand Up @@ -48,7 +49,7 @@ func init() {

func setupDB() (db *gorm.DB) {
var err error
db, err = gorm.Open(sqlite.Open("/tmp/my.db"), &gorm.Config{})
db, err = gorm.Open(postgres.Open(os.Getenv("DB_PARAMS")), &gorm.Config{})
if err != nil {
panic(err)
}
Expand Down
5 changes: 3 additions & 2 deletions docsrc/examples/example_basics/listing.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package example_basics

import (
"os"
"time"

"github.com/qor5/admin/presets"
"github.com/qor5/admin/presets/gorm2op"
v "github.com/qor5/ui/vuetify"
"github.com/qor5/web"
h "github.com/theplant/htmlgo"
"gorm.io/driver/sqlite"
"gorm.io/driver/postgres"
"gorm.io/gorm"
"gorm.io/gorm/logger"
)
Expand All @@ -21,7 +22,7 @@ func init() {

func setupDB() (db *gorm.DB) {
var err error
db, err = gorm.Open(sqlite.Open("/tmp/my.db"), &gorm.Config{})
db, err = gorm.Open(postgres.Open(os.Getenv("DB_PARAMS")), &gorm.Config{})
if err != nil {
panic(err)
}
Expand Down
6 changes: 4 additions & 2 deletions docsrc/examples/utils/db.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package utils

import (
"gorm.io/driver/sqlite"
"os"

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

func InitDB() (db *gorm.DB) {
var err error
db, err = gorm.Open(sqlite.Open("/tmp/my.db"), &gorm.Config{})
db, err = gorm.Open(postgres.Open(os.Getenv("DB_PARAMS")), &gorm.Config{})
if err != nil {
panic(err)
}
Expand Down
Loading

0 comments on commit ea0f6b7

Please sign in to comment.