-
Notifications
You must be signed in to change notification settings - Fork 79
🔥 feat: Support for DisableStartupCheck for several drivers #1927
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
base: main
Are you sure you want to change the base?
Changes from all commits
92da8e1
5652ca0
1782bd5
75a8650
c285284
2fdcd6a
02a5e61
50d99b7
9951538
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,85 +56,91 @@ store := postgres.New() | |
|
|
||
| // Initialize custom config | ||
| store := postgres.New(postgres.Config{ | ||
| DB: dbPool, | ||
| Table: "fiber_storage", | ||
| Reset: false, | ||
| GCInterval: 10 * time.Second, | ||
| DB: dbPool, | ||
| Table: "fiber_storage", | ||
| Reset: false, | ||
| GCInterval: 10 * time.Second, | ||
| }) | ||
| ``` | ||
|
|
||
| ### Config | ||
| ```go | ||
| // Config defines the config for storage. | ||
| type Config struct { | ||
| // DB pgxpool.Pool object will override connection uri and other connection fields | ||
| // | ||
| // Optional. Default is nil | ||
| DB *pgxpool.Pool | ||
|
|
||
| // Connection string to use for DB. Will override all other authentication values if used | ||
| // | ||
| // Optional. Default is "" | ||
| ConnectionURI string | ||
|
|
||
| // Host name where the DB is hosted | ||
| // | ||
| // Optional. Default is "127.0.0.1" | ||
| Host string | ||
|
|
||
| // Port where the DB is listening on | ||
| // | ||
| // Optional. Default is 5432 | ||
| Port int | ||
|
|
||
| // Server username | ||
| // | ||
| // Optional. Default is "" | ||
| Username string | ||
|
|
||
| // Server password | ||
| // | ||
| // Optional. Default is "" | ||
| Password string | ||
|
|
||
| // Database name | ||
| // | ||
| // Optional. Default is "fiber" | ||
| Database string | ||
|
|
||
| // Table name | ||
| // | ||
| // Optional. Default is "fiber_storage" | ||
| Table string | ||
|
|
||
| // The SSL mode for the connection | ||
| // | ||
| // Optional. Default is "disable" | ||
| SSLMode string | ||
|
|
||
| // Reset clears any existing keys in existing Table | ||
| // | ||
| // Optional. Default is false | ||
| Reset bool | ||
|
|
||
| // Time before deleting expired keys | ||
| // | ||
| // Optional. Default is 10 * time.Second | ||
| GCInterval time.Duration | ||
| // DB pgxpool.Pool object will override connection uri and other connection fields | ||
| // | ||
| // Optional. Default is nil | ||
| DB *pgxpool.Pool | ||
|
|
||
| // Connection string to use for DB. Will override all other authentication values if used | ||
| // | ||
| // Optional. Default is "" | ||
| ConnectionURI string | ||
|
|
||
| // Host name where the DB is hosted | ||
| // | ||
| // Optional. Default is "127.0.0.1" | ||
| Host string | ||
|
|
||
| // Port where the DB is listening on | ||
| // | ||
| // Optional. Default is 5432 | ||
| Port int | ||
|
|
||
| // Server username | ||
| // | ||
| // Optional. Default is "" | ||
| Username string | ||
|
|
||
| // Server password | ||
| // | ||
| // Optional. Default is "" | ||
| Password string | ||
|
|
||
| // Database name | ||
| // | ||
| // Optional. Default is "fiber" | ||
| Database string | ||
|
|
||
| // Table name | ||
| // | ||
| // Optional. Default is "fiber_storage" | ||
| Table string | ||
|
|
||
| // The SSL mode for the connection | ||
| // | ||
| // Optional. Default is "disable" | ||
| SSLMode string | ||
|
|
||
| // Reset clears any existing keys in existing Table | ||
| // | ||
| // Optional. Default is false | ||
| Reset bool | ||
|
|
||
| // DisableStartupCheck skips the initial connection validation during New. | ||
| // | ||
| // Optional. Default is false | ||
| DisableStartupCheck bool | ||
|
|
||
|
Comment on lines
+120
to
+124
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Docs still show Code now returns 🤖 Prompt for AI Agents |
||
| // Time before deleting expired keys | ||
| // | ||
| // Optional. Default is 10 * time.Second | ||
| GCInterval time.Duration | ||
| } | ||
| ``` | ||
|
|
||
| ### Default Config | ||
| ```go | ||
| // ConfigDefault is the default config | ||
| var ConfigDefault = Config{ | ||
| ConnectionURI: "", | ||
| Host: "127.0.0.1", | ||
| Port: 5432, | ||
| Database: "fiber", | ||
| Table: "fiber_storage", | ||
| SSLMode: "disable", | ||
| Reset: false, | ||
| GCInterval: 10 * time.Second, | ||
| ConnectionURI: "", | ||
| Host: "127.0.0.1", | ||
| Port: 5432, | ||
| Database: "fiber", | ||
| Table: "fiber_storage", | ||
| SSLMode: "disable", | ||
| Reset: false, | ||
| DisableStartupCheck: false, | ||
| GCInterval: 10 * time.Second, | ||
| } | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,45 +68,47 @@ func New(config ...Config) *Storage { | |
| } | ||
| } | ||
|
|
||
| // Ping database | ||
| if err := db.Ping(context.Background()); err != nil { | ||
| panic(err) | ||
| } | ||
|
|
||
| // Parse out schema in config, if provided | ||
| schema := "public" | ||
| tableName := cfg.Table | ||
| if strings.Contains(cfg.Table, ".") { | ||
| schema = strings.Split(cfg.Table, ".")[0] | ||
| tableName = strings.Split(cfg.Table, ".")[1] | ||
| } | ||
|
|
||
| // Drop table if set to true | ||
| if cfg.Reset { | ||
| if _, err := db.Exec(context.Background(), fmt.Sprintf(dropQuery, cfg.Table)); err != nil { | ||
| db.Close() | ||
| if !cfg.DisableStartupCheck { | ||
| // Ping database | ||
| if err := db.Ping(context.Background()); err != nil { | ||
| panic(err) | ||
| } | ||
| } | ||
|
|
||
| // Determine if table exists | ||
| tableExists := false | ||
| row := db.QueryRow(context.Background(), fmt.Sprintf(checkTableExistsQuery, schema, tableName)) | ||
| var count int | ||
| if err := row.Scan(&count); err != nil { | ||
| db.Close() | ||
| panic(err) | ||
| } | ||
| tableExists = count > 0 | ||
| // Parse out schema in config, if provided | ||
| schema := "public" | ||
| tableName := cfg.Table | ||
| if strings.Contains(cfg.Table, ".") { | ||
| schema = strings.Split(cfg.Table, ".")[0] | ||
| tableName = strings.Split(cfg.Table, ".")[1] | ||
| } | ||
|
|
||
| // Init database queries | ||
| if !tableExists { | ||
| for _, query := range initQuery { | ||
| if _, err := db.Exec(context.Background(), fmt.Sprintf(query, cfg.Table)); err != nil { | ||
| // Drop table if set to true | ||
| if cfg.Reset { | ||
| if _, err := db.Exec(context.Background(), fmt.Sprintf(dropQuery, cfg.Table)); err != nil { | ||
| db.Close() | ||
| panic(err) | ||
| } | ||
| } | ||
|
|
||
| // Determine if table exists | ||
| tableExists := false | ||
| row := db.QueryRow(context.Background(), fmt.Sprintf(checkTableExistsQuery, schema, tableName)) | ||
| var count int | ||
| if err := row.Scan(&count); err != nil { | ||
| db.Close() | ||
| panic(err) | ||
| } | ||
| tableExists = count > 0 | ||
|
|
||
| // Init database queries | ||
| if !tableExists { | ||
| for _, query := range initQuery { | ||
| if _, err := db.Exec(context.Background(), fmt.Sprintf(query, cfg.Table)); err != nil { | ||
| db.Close() | ||
| panic(err) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Create storage | ||
|
|
@@ -121,7 +123,9 @@ func New(config ...Config) *Storage { | |
| sqlGC: fmt.Sprintf("DELETE FROM %s WHERE e <= $1 AND e != 0", cfg.Table), | ||
| } | ||
|
|
||
| store.checkSchema(cfg.Table) | ||
| if !cfg.DisableStartupCheck { | ||
| store.checkSchema(cfg.Table) | ||
| } | ||
|
Comment on lines
121
to
+128
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Similar to the MySQL change, guarding the entire initialization block with Useful? React with 👍 / 👎. |
||
|
|
||
| // Start garbage collector | ||
| go store.gcTicker() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace hard tabs with spaces to comply with markdown linting rules.
The static analysis tool detected hard tabs in the documentation. The content is correct, but formatting should use spaces for consistency.
Apply this fix:
Based on static analysis hints.
Also applies to: 88-88
🧰 Tools
🪛 markdownlint-cli2 (0.18.1)
77-77: Hard tabs
Column: 1
(MD010, no-hard-tabs)
78-78: Hard tabs
Column: 1
(MD010, no-hard-tabs)
79-79: Hard tabs
Column: 1
(MD010, no-hard-tabs)
80-80: Hard tabs
Column: 1
(MD010, no-hard-tabs)
🤖 Prompt for AI Agents