<commit_before>package main

import (
	//    "labix.org/v2/mgo"
	"labix.org/v2/mgo/bson"
	"time"
)

type Entry struct {
	Id        bson.ObjectId `bson:"_id,omitempty"`
	Path      string
	Revision  int
	Value     interface{}
	Timestamp time.Time
}<commit_msg>implemented db. maybe it works. maybe it doesn't. the world may never know<commit_after>package main

import (
	"labix.org/v2/mgo"
	"labix.org/v2/mgo/bson"
	"errors"
)

type Entry struct {
	Id        bson.ObjectId `bson:"_id,omitempty"`
	Path      string
	Revision  int
	Value     []byte
}

type DB struct {
	mgoClient *mgo.Session
	c *mgo.Collection
}

func (db *DB) init(url string, database string, collection string) error{
	client, err := mgo.Dial(url)
	db.mgoClient = client
	db.c = db.mgoClient.DB(database).C(collection)
	return err;
}

func (db *DB) get(path string) (*[]byte, error){
	result := Entry{}
	err := db.c.Find(bson.M{"Path": path}).One(&result)
	return &(result.Value), err
}

func (db *DB) getTransaction(path string) (*[]byte, int, error){
	result := Entry{}
	err := db.c.Find(bson.M{"Path": path}).One(&result)
	return &(result.Value), result.Revision, err
}

func (db *DB) set(path string, value *[]byte) error{
	result := Entry{}
	change := mgo.Change{
        Update: bson.M{"$inc": bson.M{"Revision": 1}, "value": value},
	}
	_, err := db.c.Find(bson.M{"Path": path}).Apply(change, &result)
	return err
}

func (db *DB) setTransaction(path string, revision int, value *[]byte) error{
	value, rev, err := db.getTransaction(path)
	if err != nil{
		return err
	}
	if rev == revision{
		return db.set(path, value)
	}else{
		return errors.New("conflict")
	}
}

func (db *DB) delete(path string) error{
	return db.c.Remove(bson.M{"Path": path})
}

func (db *DB) close(){
	db.mgoClient.Close()
}
{'fraction_non_alphanumeric': 0.16910935738444194, 'fraction_numerical': 0.002818489289740699, 'mean_word_length': 3.8365122615803813, 'pattern_counts': {'":': 7, '<': 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': '5458233', 'n_tokens_mistral': 690, 'n_tokens_neox': 681, 'n_words': 174}