@@ -3,7 +3,6 @@ package database
33import (
44 "database/sql"
55 "encoding/json"
6-
76 "github.com/go-sql-driver/mysql"
87)
98
@@ -14,6 +13,17 @@ type MySQL struct {
1413 Config mysql.Config
1514}
1615
16+ func (m * MySQL ) Default (user , password , address , dbName string ) {
17+ m .Config = mysql.Config {
18+ User : user ,
19+ Passwd : password ,
20+ Net : "tcp" ,
21+ AllowNativePasswords : true ,
22+ Addr : address ,
23+ DBName : dbName ,
24+ }
25+ }
26+
1727// ConfigString turns our configuration into a JSON string
1828func (m * MySQL ) ConfigString () string {
1929 marshaledStruct , err := json .Marshal (m .Config )
@@ -44,7 +54,7 @@ func (m *MySQL) Connect() error {
4454}
4555
4656// SelectOne selects for a single result
47- func (m * MySQL ) SelectOne (query string , args [] any ) (interface {}, error ) {
57+ func (m * MySQL ) SelectOne (query string , args ... any ) (interface {}, error ) {
4858 var into interface {}
4959 row := m .Connection .QueryRow (query , args ... )
5060 err := row .Scan (& into )
@@ -55,7 +65,7 @@ func (m *MySQL) SelectOne(query string, args []any) (interface{}, error) {
5565}
5666
5767// Select for more than one result is expected
58- func (m * MySQL ) Select (query string , args [] any ) (* sql.Rows , error ) {
68+ func (m * MySQL ) Select (query string , args ... any ) (* sql.Rows , error ) {
5969 rows , err := m .Connection .Query (query , args ... )
6070 if err != nil {
6171 return nil , err
@@ -64,7 +74,7 @@ func (m *MySQL) Select(query string, args []any) (*sql.Rows, error) {
6474}
6575
6676// Insert a query
67- func (m * MySQL ) Insert (query string , args [] any ) (int64 , error ) {
77+ func (m * MySQL ) Insert (query string , args ... any ) (int64 , error ) {
6878 stmt , err := m .Connection .Prepare (query )
6979 if err != nil {
7080 return - 1 , err
@@ -83,7 +93,7 @@ func (m *MySQL) Insert(query string, args []any) (int64, error) {
8393}
8494
8595// Update performs an update
86- func (m * MySQL ) Update (query string , args [] any ) (int64 , error ) {
96+ func (m * MySQL ) Update (query string , args ... any ) (int64 , error ) {
8797 stmt , err := m .Connection .Prepare (query )
8898 if err != nil {
8999 return - 1 , err
@@ -102,7 +112,7 @@ func (m *MySQL) Update(query string, args []any) (int64, error) {
102112}
103113
104114// Delete performs a deletion
105- func (m * MySQL ) Delete (query string , args [] any ) (int64 , error ) {
115+ func (m * MySQL ) Delete (query string , args ... any ) (int64 , error ) {
106116 stmt , err := m .Connection .Prepare (query )
107117 if err != nil {
108118 return - 1 , err
0 commit comments