<commit_before>package aranGO

import (
	"log"
	"testing"
	"time"
)

type TestDoc struct {
	Document
	Atr1 string `json:"at,omitempty"`
	Int  int    `json:"int,omitempty"`
}

/*
func (t *TestDoc) SetDoc(d Document) {
  t.Id = d.Id
  t.Rev = d.Rev
  t.Key = d.Key
  return
}

func (t *TestDoc) SetError(d ErrorDocument){
  var er ErrorDocument
  er = d
  t.Err = &er
  return
}
*/

func Test_Database(t *testing.T) {
	/*
	  db ,err := NewDatabase("test","http://localhost:8529","diego","test")
	  log.Println(db)
	  db.Auth = true
	  db.Unsafe = true
	  db.Log = false

	  if db != nil {
	    err = db.Connect()
	    log.Println(err)
	  }

	  doc := new(TestDoc)

	  err = db.Col("test").Get("2170700199",doc)

	  log.Println(doc)
	  p :=new(TestDoc)
	  p.Int = 14

	  err = db.Col("test").Patch(doc.Key,p)
	  log.Println("document after replace:",doc)
	  log.Println("error:",err)
	  return

	  /*
	  for i:=0 ; i <= 20 ; i++{

	    doc := new(TestDoc)
	    //doc.Key = "peterete"

	    doc.Int = 25
	    doc.Atr1 = "diego"
	    doc.Array = make([]string,10)
	    doc.Array[0] = "test"
	    doc.Array[3] = "miau"

	    err = db.Col("test").Save(doc)
	  }
	  q := NewQuery("FOR i in test FILTER i.int == 14 RETURN i")
	  q.Batch = 2
	  log.Println(q)
	  q.Count = true
	  q.Validate = true

	  c , err:= db.Execute(q)
	  log.Println("query executed")

	  if err != nil {
	    log.Println("cursor error",err)
	  }else{
	  te := new(TestDoc)

	  ok, err := c.Next(te)
	  log.Println(te,ok,c.Index)
	  for ok {
	    ok, err = c.Next(te)
	    log.Println(te,ok,c.Index)
	    if err != nil{
	      log.Println(err)
	    }
	  }
	  }
	  err = db.Col("test").Delete(doc.Key)
	  log.Println(err)
	*/
}

type Counter struct {
	Document
	Amount      int   `json:"c"`
	Commission  []int `json:"pcomm"`
	Clicks      []int `json:"clicks"`
	Impressions []int `json:"impre" `
}

func NewCounter() *Counter {
	var c Counter
	c.Commission = make([]int, 24)
	c.Clicks = make([]int, 24)
	c.Impressions = make([]int, 24)
	return &c
}

func Test_T(t *testing.T) {
	s, _ := Connect("http://localhost:8529", "diego", "test", false)
	db := s.DB("test2")
	var test TestDoc
	test.Atr1 = "test"
	test.Int = 1231
	t1 := time.Now()
	err := db.Col("trans").Save(&test)
	t2 := time.Now()
	log.Println(t2.Sub(t1))

	test.Int = 23
	err = db.Col("trans").Replace(test.Key, &test)

	test.Int = 1
	err = db.Col("trans").Replace(test.Key, &test)

	cur, _ := db.Col("trans").All(0, 1)
	log.Println(cur.Result)

	// check if it exist
	log.Println(test.Document.Exist(db))

	if err != nil {

	}

	/*
		log.Println(db)
		log.Println(db.Collections)
		//
		var tra Transaction
		co := NewCounter()
		co2 := NewCounter()
		co2.Key = "tet"
		co.Key = "counter"
		t1 := time.Now()
		db.Col("trans").Save(co2)
		t2 := time.Now()
		// Relate both counter
		//err := db.Col("rela").SaveEdge(map[string]interface{}{"pirchicho": "loco", "send": true}, "trans/tet", "trans/counter")
		//log.Print(err)<commit_msg>database test - model<commit_after>package aranGO

import (
	"fmt"
	"log"
	"testing"
	"time"
)

type TestDoc struct {
	Document
	Atr1 string `json:"at,omitempty" enum:"A,M,S"`
	Int  string `json:"int,omitempty" required:"-"`
	Sub  SubDoc `json:"doc" sub:"-"`
}

type SubDoc struct {
	Requi string `json:"q" required:"-"`
}

// implement modeler
func (t *TestDoc) GetKey() string {
	return t.Key
}

func (t *TestDoc) GetCollection() string {
	return "trans"
}

func (t *TestDoc) GetError() (string, bool) {
	return t.Message, t.Error
}

func (t *TestDoc) PreSave(err Error) {
	fmt.Println("presave hook")
	return
}

func (t *TestDoc) PostSave(err Error) {
	fmt.Println("postsave hook")
	return
}

func (t *TestDoc) PreUpdate(err Error) {
	fmt.Println("preupdate hook")
	return
}

func (t *TestDoc) PostUpdate(err Error) {
	fmt.Println("post update hook")
	return
}

func (t *TestDoc) PreDelete(err Error) {
	fmt.Println("pre delete hook")
	return
}

func (t *TestDoc) PostDelete(err Error) {
	fmt.Println("post delete hook")
	return
}

/*
func (t *TestDoc) SetDoc(d Document) {
  t.Id = d.Id
  t.Rev = d.Rev
  t.Key = d.Key
  return
}

func (t *TestDoc) SetError(d ErrorDocument){
  var er ErrorDocument
  er = d
  t.Err = &er
  return
}
*/

func Test_Database(t *testing.T) {
	/*
	  db ,err := NewDatabase("test","http://localhost:8529","diego","test")
	  log.Println(db)
	  db.Auth = true
	  db.Unsafe = true
	  db.Log = false

	  if db != nil {
	    err = db.Connect()
	    log.Println(err)
	  }

	  doc := new(TestDoc)

	  err = db.Col("test").Get("2170700199",doc)

	  log.Println(doc)
	  p :=new(TestDoc)
	  p.Int = 14

	  err = db.Col("test").Patch(doc.Key,p)
	  log.Println("document after replace:",doc)
	  log.Println("error:",err)
	  return

	  /*
	  for i:=0 ; i <= 20 ; i++{

	    doc := new(TestDoc)
	    //doc.Key = "peterete"

	    doc.Int = 25
	    doc.Atr1 = "diego"
	    doc.Array = make([]string,10)
	    doc.Array[0] = "test"
	    doc.Array[3] = "miau"

	    err = db.Col("test").Save(doc)
	  }
	  q := NewQuery("FOR i in test FILTER i.int == 14 RETURN i")
	  q.Batch = 2
	  log.Println(q)
	  q.Count = true
	  q.Validate = true

	  c , err:= db.Execute(q)
	  log.Println("query executed")

	  if err != nil {
	    log.Println("cursor error",err)
	  }else{
	  te := new(TestDoc)

	  ok, err := c.Next(te)
	  log.Println(te,ok,c.Index)
	  for ok {
	    ok, err = c.Next(te)
	    log.Println(te,ok,c.Index)
	    if err != nil{
	      log.Println(err)
	    }
	  }
	  }
	  err = db.Col("test").Delete(doc.Key)
	  log.Println(err)
	*/
}

type Counter struct {
	Document
	Amount      int   `json:"c"`
	Commission  []int `json:"pcomm"`
	Clicks      []int `json:"clicks"`
	Impressions []int `json:"impre" `
}

func NewCounter() *Counter {
	var c Counter
	c.Commission = make([]int, 24)
	c.Clicks = make([]int, 24)
	c.Impressions = make([]int, 24)
	return &c
}

func Test_T(t *testing.T) {
	s, _ := Connect("http://localhost:8529", "diego", "test", false)
	db := s.DB("test2")
	var test TestDoc
	test.Atr1 = "A"
	test.Int = "test2"
	test.Sub.Requi = "miau"

	t0 := time.Now()
	log.Println(Save(db, &test))
	t1 := time.Now()
	log.Println(test)
	test.Atr1 = "M"

	log.Println(Save(db, &test))

	log.Println(t1.Sub(t0))
	/*
		log.Println(db)
		log.Println(db.Collections)
		//
		var tra Transaction
		co := NewCounter()
		co2 := NewCounter()
		co2.Key = "tet"
		co.Key = "counter"
		t1 := time.Now()
		db.Col("trans").Save(co2)
		t2 := time.Now()
		// Relate both counter
		//err := db.Col("rela").SaveEdge(map[string]interface{}{"pirchicho": "loco", "send": true}, "trans/tet", "trans/counter")
		//log.Print(err)
{'fraction_non_alphanumeric': 0.18596171376481313, 'fraction_numerical': 0.017168034032209054, 'mean_word_length': 2.953753753753754, 'pattern_counts': {'":': 4, '<': 5, '<?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': '4776145', 'n_tokens_mistral': 2926, 'n_tokens_neox': 2674, 'n_words': 580}