fix: properly parse mysql connection string, docs update (#730)

Mysql connection string update, docs update
This commit is contained in:
András Rutkai 2023-09-13 18:31:41 +02:00 committed by GitHub
parent 1d52569731
commit e722cb6961
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 29 deletions

5
.gitignore vendored
View file

@ -1,5 +1,8 @@
# Exclude config file # Exclude IDE
.vscode/ .vscode/
.idea/
# Exclude config file
*.toml *.toml
# Exclude executable file # Exclude executable file

View file

@ -16,18 +16,9 @@ services:
- "postgres" - "postgres"
- "mariadb" - "mariadb"
environment: environment:
SHIORI_DBMS: mysql
SHIORI_DIR: /srv/shiori SHIORI_DIR: /srv/shiori
SHIORI_PG_USER: shiori #SHIORI_DATABASE_URL: mysql://shiori:shiori@(mariadb)/shiori?charset=utf8mb4
SHIORI_PG_PASS: shiori SHIORI_DATABASE_URL: postgres://shiori:shiori@postgres/shiori?sslmode=disable
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)
postgres: postgres:
image: postgres:15 image: postgres:15

View file

@ -35,22 +35,12 @@ Shiori uses an SQLite3 database stored in the above data directory by default. I
### MySQL ### MySQL
| Variable | Description | MySQL example: `SHIORI_DATABASE_URL="mysql://username:password@(hostname:port)/database?charset=utf8mb4"`
|------------------------|-----------------------------------------------------|
| `SHIORI_DBMS` | Must be set to `mysql` | You can find additional details in [go mysql sql driver documentation](https://github.com/go-sql-driver/mysql#dsn-data-source-name).
| `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)` |
### PostgreSQL ### PostgreSQL
| Variable | Description | PostgreSQL example: `SHIORI_DATABASE_URL="postgres://pqgotest:password@hostname/database?sslmode=verify-full"`
|---------------------|-----------------------------------------------------|
| `SHIORI_DBMS` | Must be set to `postgresql` | You can find additional details in [go postgres sql driver documentation](https://pkg.go.dev/github.com/lib/pq).
| `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`) |

View file

@ -6,6 +6,7 @@ import (
"fmt" "fmt"
"log" "log"
"net/url" "net/url"
"strings"
"github.com/go-shiori/shiori/internal/model" "github.com/go-shiori/shiori/internal/model"
"github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx"
@ -54,7 +55,8 @@ func Connect(ctx context.Context, dbURL string) (DB, error) {
switch dbU.Scheme { switch dbU.Scheme {
case "mysql": case "mysql":
return OpenMySQLDatabase(ctx, dbURL) urlNoSchema := strings.Split(dbURL, "://")[1]
return OpenMySQLDatabase(ctx, urlNoSchema)
case "postgres": case "postgres":
return OpenPGDatabase(ctx, dbURL) return OpenPGDatabase(ctx, dbURL)
case "sqlite": case "sqlite":