<commit_before>// Package fridgedb provides toplevel operations on database
package fridgedb

import (
	"database/sql"
	"fmt"
	"log"
	"os"
	"time"

	"github.com/andriykohut/moldyfridge/models"
	_ "github.com/mattn/go-sqlite3"
)

type MoldyFridge struct {
	DbName string
	Db     *sql.DB
}

func NewFridge(dbname string) *MoldyFridge {
	db, err := sql.Open("sqlite3", dbname)
	if err != nil {
		log.Fatal("Can't create new fridge")
		log.Fatal(err)
	}
	return &MoldyFridge{DbName: dbname, Db: db}
}

func (f *MoldyFridge) Init() {
	query := "create table food (id integer not null primary key, name text, amount integer, added integer);"
	_, err := f.Db.Exec(query)
	if err != nil {
		log.Print("can't initialize table")
		log.Fatal(err)
	}
}

func (f *MoldyFridge) CheckDb() bool {
	_, err := f.Db.Exec("select id from food limit 1;")
	return err != nil
}

func (f *MoldyFridge) Destroy() {
	f.Db.Close()
	os.Remove(f.DbName)
}

func (f *MoldyFridge) AddFood(name string, amount int) {
	now := time.Now().Unix()
	fmt.Println(now)
	query := fmt.Sprintf("insert into food (name, amount, added) values ('%s', %d, %d);", name, amount, now)
	_, err := f.Db.Exec(query)
	if err != nil {
		log.Printf("Can't add %s\n", name)
		log.Fatal(err)
	}
}

func (f *MoldyFridge) RemoveFood(args ...interface{}) {
	name := args[0].(string)
	amount := 0
	var query string
	if len(args) == 2 {
		amount = args[1].(int)
	}<commit_msg>remove print<commit_after>// Package fridgedb provides toplevel operations on database
package fridgedb

import (
	"database/sql"
	"fmt"
	"log"
	"os"
	"time"

	"github.com/andriykohut/moldyfridge/models"
	_ "github.com/mattn/go-sqlite3"
)

type MoldyFridge struct {
	DbName string
	Db     *sql.DB
}

func NewFridge(dbname string) *MoldyFridge {
	db, err := sql.Open("sqlite3", dbname)
	if err != nil {
		log.Fatal("Can't create new fridge")
		log.Fatal(err)
	}
	return &MoldyFridge{DbName: dbname, Db: db}
}

func (f *MoldyFridge) Init() {
	query := "create table food (id integer not null primary key, name text, amount integer, added integer);"
	_, err := f.Db.Exec(query)
	if err != nil {
		log.Print("can't initialize table")
		log.Fatal(err)
	}
}

func (f *MoldyFridge) CheckDb() bool {
	_, err := f.Db.Exec("select id from food limit 1;")
	return err != nil
}

func (f *MoldyFridge) Destroy() {
	f.Db.Close()
	os.Remove(f.DbName)
}

func (f *MoldyFridge) AddFood(name string, amount int) {
	now := time.Now().Unix()
	query := fmt.Sprintf("insert into food (name, amount, added) values ('%s', %d, %d);", name, amount, now)
	_, err := f.Db.Exec(query)
	if err != nil {
		log.Printf("Can't add %s\n", name)
		log.Fatal(err)
	}
}

func (f *MoldyFridge) RemoveFood(args ...interface{}) {
	name := args[0].(string)
	amount := 0
	var query string
	if len(args) == 2 {
		amount = args[1].(int)
	}
{'fraction_non_alphanumeric': 0.16708229426433915, 'fraction_numerical': 0.004987531172069825, 'mean_word_length': 3.91768826619965, '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': '6396627', 'n_tokens_mistral': 1175, 'n_tokens_neox': 1129, 'n_words': 294}