<commit_before>package db

import (
	"launchpad.net/mgo"
	"sync"
)

type Storage struct {
	collections map[string]*mgo.Collection
	session     *mgo.Session
	sync.Mutex
}

func Open(addr string) (*Storage, error) {
	session, err := mgo.Dial(addr)
	if err != nil {
		return nil, err
	}
	s := &Storage{
		session:     session,
		collections: make(map[string]*mgo.Collection),
	}
	return s, nil
}

func (s *Storage) Close() {
	s.session.Close()
}

func (s *Storage) getCollection(name string) *mgo.Collection {
	collection, ok := s.collections[name]
	if !ok {
		collection = s.session.DB("tsuru").C(name)
		s.collections[name] = collection
	}
	return collection
}

func (s *Storage) Apps() *mgo.Collection {
	return s.getCollection("apps")
}

func (s *Storage) Services() *mgo.Collection {
	return s.getCollection("services")
}

func (s *Storage) Units() *mgo.Collection {
	return s.getCollection("units")
}

func (s *Storage) Users() *mgo.Collection {
	emailIndex := mgo.Index{Key: []string{"email"}, Unique: true}
	c := s.getCollection("users")
	c.EnsureIndex(emailIndex)
	return c
}
<commit_msg>db: added method on Storage to drop the database<commit_after>package db

import (
	"launchpad.net/mgo"
	"sync"
)

type Storage struct {
	collections map[string]*mgo.Collection
	session     *mgo.Session
	sync.Mutex
}

func Open(addr string) (*Storage, error) {
	session, err := mgo.Dial(addr)
	if err != nil {
		return nil, err
	}
	s := &Storage{
		session:     session,
		collections: make(map[string]*mgo.Collection),
	}
	return s, nil
}

func (s *Storage) Close() {
	s.session.Close()
}

func (s *Storage) getCollection(name string) *mgo.Collection {
	collection, ok := s.collections[name]
	if !ok {
		collection = s.session.DB("tsuru").C(name)
		s.collections[name] = collection
	}
	return collection
}

func (s *Storage) Apps() *mgo.Collection {
	return s.getCollection("apps")
}

func (s *Storage) Services() *mgo.Collection {
	return s.getCollection("services")
}

func (s *Storage) Units() *mgo.Collection {
	return s.getCollection("units")
}

func (s *Storage) Users() *mgo.Collection {
	emailIndex := mgo.Index{Key: []string{"email"}, Unique: true}
	c := s.getCollection("users")
	c.EnsureIndex(emailIndex)
	return c
}

func (s *Storage) DropDB() error {
	return s.session.DB("tsuru").DropDatabase()
}

{'fraction_non_alphanumeric': 0.15741543798785776, 'fraction_numerical': 0.0, 'mean_word_length': 4.453900709219858, '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': '4840974', 'n_tokens_mistral': 854, 'n_tokens_neox': 837, 'n_words': 203}