mirror of https://github.com/fmartingr/shiori.git
Explicit charset for MySQL connection
This commit is contained in:
parent
a5cb2c6e40
commit
32f9d2695f
|
@ -122,7 +122,7 @@ func openMySQLDatabase() (database.DB, error) {
|
|||
dbName, _ := os.LookupEnv("SHIORI_MYSQL_NAME")
|
||||
dbAddress, _ := os.LookupEnv("SHIORI_MYSQL_ADDRESS")
|
||||
|
||||
connString := fmt.Sprintf("%s:%s@%s/%s", user, password, dbAddress, dbName)
|
||||
connString := fmt.Sprintf("%s:%s@%s/%s?charset=utf8mb4", user, password, dbAddress, dbName)
|
||||
return database.OpenMySQLDatabase(connString)
|
||||
}
|
||||
|
||||
|
|
|
@ -113,7 +113,7 @@ func (db *MySQLDatabase) SaveBookmarks(bookmarks ...model.Bookmark) (result []mo
|
|||
stmtInsertBook, err := tx.Preparex(`INSERT INTO bookmark
|
||||
(id, url, title, excerpt, author, public, content, html, modified)
|
||||
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
ON DUPLICATE KEY UPDATE
|
||||
url = VALUES(url),
|
||||
title = VALUES(title),
|
||||
excerpt = VALUES(excerpt),
|
||||
|
@ -241,7 +241,7 @@ func (db *MySQLDatabase) GetBookmarks(opts GetBookmarksOptions) ([]model.Bookmar
|
|||
// Add where clause for search keyword
|
||||
if opts.Keyword != "" {
|
||||
query += ` AND (
|
||||
url LIKE ? OR
|
||||
url LIKE ? OR
|
||||
MATCH(title, excerpt, content) AGAINST (? IN BOOLEAN MODE)
|
||||
)`
|
||||
|
||||
|
@ -329,10 +329,10 @@ func (db *MySQLDatabase) GetBookmarks(opts GetBookmarksOptions) ([]model.Bookmar
|
|||
}
|
||||
|
||||
// Fetch tags for each bookmarks
|
||||
stmtGetTags, err := db.Preparex(`SELECT t.id, t.name
|
||||
FROM bookmark_tag bt
|
||||
stmtGetTags, err := db.Preparex(`SELECT t.id, t.name
|
||||
FROM bookmark_tag bt
|
||||
LEFT JOIN tag t ON bt.tag_id = t.id
|
||||
WHERE bt.bookmark_id = ?
|
||||
WHERE bt.bookmark_id = ?
|
||||
ORDER BY t.name`)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to prepare tag query: %v", err)
|
||||
|
@ -369,7 +369,7 @@ func (db *MySQLDatabase) GetBookmarksCount(opts GetBookmarksOptions) (int, error
|
|||
// Add where clause for search keyword
|
||||
if opts.Keyword != "" {
|
||||
query += ` AND (
|
||||
url LIKE ? OR
|
||||
url LIKE ? OR
|
||||
MATCH(title, excerpt, content) AGAINST (? IN BOOLEAN MODE)
|
||||
)`
|
||||
|
||||
|
@ -497,7 +497,7 @@ func (db *MySQLDatabase) DeleteBookmarks(ids ...int) (err error) {
|
|||
func (db *MySQLDatabase) GetBookmark(id int, url string) (model.Bookmark, bool) {
|
||||
args := []interface{}{id}
|
||||
query := `SELECT
|
||||
id, url, title, excerpt, author, public,
|
||||
id, url, title, excerpt, author, public,
|
||||
content, html, modified, content <> '' has_content
|
||||
FROM bookmark WHERE id = ?`
|
||||
|
||||
|
@ -562,7 +562,7 @@ func (db *MySQLDatabase) GetAccounts(opts GetAccountsOptions) ([]model.Account,
|
|||
// Returns the account and boolean whether it's exist or not.
|
||||
func (db *MySQLDatabase) GetAccount(username string) (model.Account, bool) {
|
||||
account := model.Account{}
|
||||
db.Get(&account, `SELECT
|
||||
db.Get(&account, `SELECT
|
||||
id, username, password, owner FROM account WHERE username = ?`,
|
||||
username)
|
||||
|
||||
|
@ -603,8 +603,8 @@ func (db *MySQLDatabase) DeleteAccounts(usernames ...string) (err error) {
|
|||
// GetTags fetch list of tags and their frequency.
|
||||
func (db *MySQLDatabase) GetTags() ([]model.Tag, error) {
|
||||
tags := []model.Tag{}
|
||||
query := `SELECT bt.tag_id id, t.name, COUNT(bt.tag_id) n_bookmarks
|
||||
FROM bookmark_tag bt
|
||||
query := `SELECT bt.tag_id id, t.name, COUNT(bt.tag_id) n_bookmarks
|
||||
FROM bookmark_tag bt
|
||||
LEFT JOIN tag t ON bt.tag_id = t.id
|
||||
GROUP BY bt.tag_id ORDER BY t.name`
|
||||
|
||||
|
|
Loading…
Reference in New Issue