mirror of
https://github.com/go-shiori/shiori.git
synced 2024-09-20 06:56:10 +08:00
fix: properly parse mysql connection string, docs update (#730)
Mysql connection string update, docs update
This commit is contained in:
parent
1d52569731
commit
e722cb6961
5
.gitignore
vendored
5
.gitignore
vendored
|
@ -1,5 +1,8 @@
|
|||
# Exclude config file
|
||||
# Exclude IDE
|
||||
.vscode/
|
||||
.idea/
|
||||
|
||||
# Exclude config file
|
||||
*.toml
|
||||
|
||||
# Exclude executable file
|
||||
|
|
|
@ -16,18 +16,9 @@ services:
|
|||
- "postgres"
|
||||
- "mariadb"
|
||||
environment:
|
||||
SHIORI_DBMS: mysql
|
||||
SHIORI_DIR: /srv/shiori
|
||||
SHIORI_PG_USER: shiori
|
||||
SHIORI_PG_PASS: shiori
|
||||
SHIORI_PG_NAME: shiori
|
||||
SHIORI_PG_HOST: postgres
|
||||
SHIORI_PG_PORT: 5432
|
||||
SHIORI_PG_SSLMODE: disable
|
||||
SHIORI_MYSQL_USER: shiori
|
||||
SHIORI_MYSQL_PASS: shiori
|
||||
SHIORI_MYSQL_NAME: shiori
|
||||
SHIORI_MYSQL_ADDRESS: (mariadb)
|
||||
#SHIORI_DATABASE_URL: mysql://shiori:shiori@(mariadb)/shiori?charset=utf8mb4
|
||||
SHIORI_DATABASE_URL: postgres://shiori:shiori@postgres/shiori?sslmode=disable
|
||||
|
||||
postgres:
|
||||
image: postgres:15
|
||||
|
|
|
@ -35,22 +35,12 @@ Shiori uses an SQLite3 database stored in the above data directory by default. I
|
|||
|
||||
### MySQL
|
||||
|
||||
| Variable | Description |
|
||||
|------------------------|-----------------------------------------------------|
|
||||
| `SHIORI_DBMS` | Must be set to `mysql` |
|
||||
| `SHIORI_MYSQL_USER` | Name of MySQL user |
|
||||
| `SHIORI_MYSQL_PASS` | Password for the above user |
|
||||
| `SHIORI_MYSQL_NAME` | Name of database to use |
|
||||
| `SHIORI_MYSQL_ADDRESS` | Address of MySQL server, e.g. `tcp(127.0.0.1:3306)` or `unix(/tmp/mysqld.sock)` |
|
||||
MySQL example: `SHIORI_DATABASE_URL="mysql://username:password@(hostname:port)/database?charset=utf8mb4"`
|
||||
|
||||
You can find additional details in [go mysql sql driver documentation](https://github.com/go-sql-driver/mysql#dsn-data-source-name).
|
||||
|
||||
### PostgreSQL
|
||||
|
||||
| Variable | Description |
|
||||
|---------------------|-----------------------------------------------------|
|
||||
| `SHIORI_DBMS` | Must be set to `postgresql` |
|
||||
| `SHIORI_PG_USER` | Name of PostgreSQL user |
|
||||
| `SHIORI_PG_PASS` | Password for the above user |
|
||||
| `SHIORI_PG_NAME` | Name of database to use |
|
||||
| `SHIORI_PG_HOST` | Address of PostgreSQL server |
|
||||
| `SHIORI_PG_PORT` | Port number used by PostgreSQL server |
|
||||
| `SHIORI_PG_SSLMODE` | PostgreSQL connection SSL mode (default: `disable`) |
|
||||
PostgreSQL example: `SHIORI_DATABASE_URL="postgres://pqgotest:password@hostname/database?sslmode=verify-full"`
|
||||
|
||||
You can find additional details in [go postgres sql driver documentation](https://pkg.go.dev/github.com/lib/pq).
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"fmt"
|
||||
"log"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/go-shiori/shiori/internal/model"
|
||||
"github.com/jmoiron/sqlx"
|
||||
|
@ -54,7 +55,8 @@ func Connect(ctx context.Context, dbURL string) (DB, error) {
|
|||
|
||||
switch dbU.Scheme {
|
||||
case "mysql":
|
||||
return OpenMySQLDatabase(ctx, dbURL)
|
||||
urlNoSchema := strings.Split(dbURL, "://")[1]
|
||||
return OpenMySQLDatabase(ctx, urlNoSchema)
|
||||
case "postgres":
|
||||
return OpenPGDatabase(ctx, dbURL)
|
||||
case "sqlite":
|
||||
|
|
Loading…
Reference in a new issue