You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Documents the new constructors for using existing database connections
with SQLite, MySQL, and PostgreSQL backends, including:
- Usage examples
- Migration handling differences
- MySQL-specific WithMigrationDSN option
If you already have a `*sql.DB` connection, you can use `NewSqliteBackendWithDB` to create a backend that uses your existing connection. When using this constructor:
31
+
32
+
- The backend will **not** close the database connection when `Close()` is called
33
+
- Migrations are **disabled by default** - use `WithApplyMigrations(true)` to enable them
34
+
- You are responsible for configuring the connection appropriately (e.g., WAL mode, busy timeout, max open connections)
- `WithApplyMigrations(applyMigrations bool)` - Set whether migrations should be applied on startup. Defaults to `true`
47
+
- `WithApplyMigrations(applyMigrations bool)` - Set whether migrations should be applied on startup. Defaults to `true` for `NewSqliteBackend`, `false` for `NewSqliteBackendWithDB`
If you already have a `*sql.DB` connection, you can use `NewMysqlBackendWithDB` to create a backend that uses your existing connection. When using this constructor:
75
+
76
+
- The backend will **not** close the database connection when `Close()` is called
77
+
- Migrations are **disabled by default**
78
+
- To enable migrations, you must provide a DSN with `WithMigrationDSN()` that supports multi-statement queries
- `WithMySQLOptions(f func(db *sql.DB))` - Apply custom options to the MySQL database connection
50
-
- `WithApplyMigrations(applyMigrations bool)` - Set whether migrations should be applied on startup. Defaults to `true`
95
+
- `WithApplyMigrations(applyMigrations bool)` - Set whether migrations should be applied on startup. Defaults to `true` for `NewMysqlBackend`, `false` for `NewMysqlBackendWithDB`
96
+
- `WithMigrationDSN(dsn string)` - Set the DSN to use for migrations. Required when using `NewMysqlBackendWithDB` with `ApplyMigrations` enabled. The DSN must support multi-statement queries.
If you already have a `*sql.DB` connection, you can use `NewPostgresBackendWithDB` to create a backend that uses your existing connection. When using this constructor:
125
+
126
+
- The backend will **not** close the database connection when `Close()` is called
127
+
- Migrations are **disabled by default** - use `WithApplyMigrations(true)` to enable them
- `WithPostgresOptions(f func(db *sql.DB))` - Apply custom options to the PostgreSQL database connection
75
-
- `WithApplyMigrations(applyMigrations bool)` - Set whether migrations should be applied on startup. Defaults to `true`
138
+
- `WithApplyMigrations(applyMigrations bool)` - Set whether migrations should be applied on startup. Defaults to `true` for `NewPostgresBackend`, `false` for `NewPostgresBackendWithDB`
0 commit comments