Now can do all CRUD and just need search and pagination.

This commit is contained in:
Zed A. Shaw 2025-07-27 11:22:33 -04:00
parent b0ba0c7e16
commit e178ca6733
5 changed files with 62 additions and 10 deletions

View file

@ -47,7 +47,7 @@ func Delete(table string, id int64) error {
return err
}
func Insert(table string, value reflect.Value) error {
func Insert(table string, value reflect.Value) (int64, int64, error) {
type_of := value.Type()
field_num := value.NumField()
var columns []string
@ -64,9 +64,14 @@ func Insert(table string, value reflect.Value) error {
builder := sq.Insert(table).Columns(columns...).Values(values...)
sql_query, args, err := builder.ToSql()
_, err = data.DB.Exec(sql_query, args...)
result, err := data.DB.Exec(sql_query, args...)
id, err := result.LastInsertId()
if err != nil { return -1, -1, err }
return err
count, err := result.RowsAffected()
if err != nil { return id, -1, err }
return id, count, err
}
func Update(table string, value reflect.Value) error {