package sriracha import ( "database/sql" "reflect" ) // TODO cache type expansion into name and list of fields and their types var db *sql.DB func connectDB(driver string, dataSource string) error { var err error db, err = sql.Open(driver, dataSource) return err } func dbCreate[T any](db *sql.DB) error { var query string _, err := db.Exec(query) return err } func dbByID[T any](db *sql.DB, table string, id int) (*T, error) { var columns string getRow := func() *sql.Row { return db.QueryRow("SELECT " + columns + " FROM " + table + " WHERE id = ?") } var v T switch node := any(v).(type) { case *Account: columns = "id, username, password" err := getRow().Scan(&node.ID) if err != nil { return nil, err } } return &v, nil } func StartTransaction() error { _, err := db.Exec("BEGIN") return err } func CancelTransaction() error { _, err := db.Exec("ROLLBACK") return err } func CommitTransaction() error { _, err := db.Exec("COMMIT") return err } func CreateAccount(account *Account) error { //TODO implement me panic("implement me") } func AccountByID(id int) (*Account, error) { //TODO implement me panic("implement me") } func AccountByName(name string) (*Account, error) { //TODO implement me panic("implement me") } func Accounts() ([]*Account, error) { //TODO implement me panic("implement me") } func UpdateAccount(account *Account) error { //TODO implement me panic("implement me") } func DeleteAccount(account *Account) error { //TODO implement me panic("implement me") } func CreateBan(Ban *Ban) error { //TODO implement me panic("implement me") } func BanByID(id int) (*Ban, error) { //TODO implement me panic("implement me") } func BanByName(name string) (*Ban, error) { //TODO implement me panic("implement me") } func Bans() ([]*Ban, error) { //TODO implement me panic("implement me") } func UpdateBan(Ban *Ban) error { //TODO implement me panic("implement me") } func DeleteBan(Ban *Ban) error { //TODO implement me panic("implement me") } func CreateKeyword(Keyword *Keyword) error { //TODO implement me panic("implement me") } func KeywordByID(id int) (*Keyword, error) { //TODO implement me panic("implement me") } func KeywordByName(name string) (*Keyword, error) { //TODO implement me panic("implement me") } func Keywords() ([]*Keyword, error) { //TODO implement me panic("implement me") } func UpdateKeyword(Keyword *Keyword) error { //TODO implement me panic("implement me") } func DeleteKeyword(Keyword *Keyword) error { //TODO implement me panic("implement me") } func CreateLog(Log *Log) error { //TODO implement me panic("implement me") } func LogByID(id int) (*Log, error) { //TODO implement me panic("implement me") } func LogByName(name string) (*Log, error) { //TODO implement me panic("implement me") } func Logs() ([]*Log, error) { //TODO implement me panic("implement me") } func UpdateLog(Log *Log) error { //TODO implement me panic("implement me") } func DeleteLog(Log *Log) error { //TODO implement me panic("implement me") } func CreatePost(Post *Post) error { //TODO implement me panic("implement me") } func PostByID(id int) (*Post, error) { //TODO implement me panic("implement me") } func PostByName(name string) (*Post, error) { //TODO implement me panic("implement me") } func Posts() ([]*Post, error) { //TODO implement me panic("implement me") } func UpdatePost(Post *Post) error { //TODO implement me panic("implement me") } func DeletePost(Post *Post) error { //TODO implement me panic("implement me") } func CreateReport(Report *Report) error { //TODO implement me panic("implement me") } func ReportByID(id int) (*Report, error) { //TODO implement me panic("implement me") } func ReportByName(name string) (*Report, error) { //TODO implement me panic("implement me") } func Reports() ([]*Report, error) { //TODO implement me panic("implement me") } func UpdateReport(Report *Report) error { //TODO implement me panic("implement me") } func DeleteReport(Report *Report) error { //TODO implement me panic("implement me") } func reflectName(v interface{}) string { sV := reflect.ValueOf(v) sT := reflect.TypeOf(v) if sV.Kind() == reflect.Ptr { sV = sV.Elem() sT = sT.Elem() } return sV.Type().String() }