Personal Git forge.

Code git clone ssh://git.poy.ooo:6969/~poyo/farga ZIP
db/gists.go / 1KiB #ef0bb50a
Raw
package dbimport (	"farga/db/types"	"github.com/google/uuid"	"gorm.io/gorm/clause")// creates a new gist and assigns it to a user.func (db *DB) NewGist(userID uuid.UUID, title string, content string) (types.Gist, error) {	gist := types.Gist{		UserID:  userID,		Title:   title,		Content: content,	}	err := db.Create(&gist).Error	return gist, err}// gets a gist. will error if it doesn't exist.func (db *DB) GetGist(id uuid.UUID) (gist types.Gist, err error) {	err = db.Preload(clause.Associations).Where("id = ?", id).First(&gist).Error	return gist, err}// deletes any given gist by ID.func (db *DB) DeleteGist(id uuid.UUID) error {	return db.Delete(&types.Gist{UUID_ID: types.UUID_ID{ID: id}}).Error}// updates a given gist.func (db *DB) UpdateGist(id uuid.UUID, title string, content string) (types.Gist, error) {	gist := types.Gist{		UUID_ID: types.UUID_ID{			ID: id,		},	}	err := db.Model(&gist).Select("title", "content").Updates(types.Gist{Title: title, Content: content}).Error	return gist, err}