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/
|
.vscode/
|
||||||
|
.idea/
|
||||||
|
|
||||||
|
# Exclude config file
|
||||||
*.toml
|
*.toml
|
||||||
|
|
||||||
# Exclude executable file
|
# Exclude executable 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
|
||||||
|
|
|
@ -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`) |
|
|
||||||
|
|
|
@ -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":
|
||||||
|
|
Loading…
Reference in a new issue