<commit_before>package models

import (
	"database/sql"
	"errors"

	"github.com/eirka/eirka-libs/db"
	e "github.com/eirka/eirka-libs/errors"
)

type DeleteImageTagModel struct {
	Image uint
	Tag   uint
	Name  string
	Ib    uint
}

// check struct validity
func (d *DeleteImageTagModel) IsValid() bool {

	if d.Image == 0 {
		return false
	}

	if d.Tag == 0 {
		return false
	}

	if d.Name == "" {
		return false
	}

	if d.Ib == 0 {
		return false
	}

	return true

}

// Status will return info
func (i *DeleteImageTagModel) Status() (err error) {

	// Get Database handle
	dbase, err := db.GetDb()
	if err != nil {
		return
	}

	// Check if the tag is there
	err = dbase.QueryRow("SELECT tag_name FROM tags WHERE tag_id = ? AND ib_id = ? LIMIT 1", i.Tag, i.Ib).Scan(&i.Name)
	if err == sql.ErrNoRows {
		return e.ErrNotFound
	} else if err != nil {
		return
	}

	return

}

// Delete will remove the entry
func (i *DeleteImageTagModel) Delete() (err error) {

	// check model validity
	if !i.IsValid() {
		return errors.New("DeleteImageTagModel is not valid")
	}

	// Get Database handle
	dbase, err := db.GetDb()
	if err != nil {
		return
	}

	ps1, err := dbase.Prepare("DELETE FROM tagmap WHERE image_id = ? AND tag_id = ? AND ib_id = ? LIMIT 1")
	if err != nil {
		return
	}
	defer ps1.Close()

	_, err = ps1.Exec(i.Image, i.Tag, i.Ib)
	if err != nil {
		return
	}

	return

}<commit_msg>use ib from params<commit_after>package models

import (
	"database/sql"
	"errors"

	"github.com/eirka/eirka-libs/db"
	e "github.com/eirka/eirka-libs/errors"
)

type DeleteImageTagModel struct {
	Image uint
	Tag   uint
	Name  string
	Ib    uint
}

// check struct validity
func (d *DeleteImageTagModel) IsValid() bool {

	if d.Image == 0 {
		return false
	}

	if d.Tag == 0 {
		return false
	}

	if d.Name == "" {
		return false
	}

	if d.Ib == 0 {
		return false
	}

	return true

}

// Status will return info
func (i *DeleteImageTagModel) Status() (err error) {

	// Get Database handle
	dbase, err := db.GetDb()
	if err != nil {
		return
	}

	// Check if the tag is there
	err = dbase.QueryRow("SELECT tag_name FROM tags WHERE tag_id = ? AND ib_id = ? LIMIT 1", i.Tag, i.Ib).Scan(&i.Name)
	if err == sql.ErrNoRows {
		return e.ErrNotFound
	} else if err != nil {
		return
	}

	return

}

// Delete will remove the entry
func (i *DeleteImageTagModel) Delete() (err error) {

	// check model validity
	if !i.IsValid() {
		return errors.New("DeleteImageTagModel is not valid")
	}

	// Get Database handle
	dbase, err := db.GetDb()
	if err != nil {
		return
	}

	ps1, err := dbase.Prepare("DELETE FROM tagmap INNER JOIN tags ON tagmap.tag_id = tags.tag_id WHERE image_id = ? AND tagmap.tag_id = ? AND ib_id = ? LIMIT 1")
	if err != nil {
		return
	}
	defer ps1.Close()

	_, err = ps1.Exec(i.Image, i.Tag, i.Ib)
	if err != nil {
		return
	}

	return

}
{'fraction_non_alphanumeric': 0.12944073162152656, 'fraction_numerical': 0.005627857896588111, 'mean_word_length': 2.8746594005449593, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6310527', 'n_tokens_mistral': 1155, 'n_tokens_neox': 1088, 'n_words': 323}