8000 Database query with time.Time · Issue #87 · kelindar/column · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Database query with time.Time #87
Closed
@roihe

Description

@roihe

Hi, I have a question about the BinaryMarshaler with the datatype time.Time.
When I make a query with txn.WithValue I can not compare with the datatype time.Time.
The comparison is always false. I've already tried a few things to convert the value before comparing.
Here's a short example. The problem is in the line 'which datatyp should I use here?'

func main() {
	table := column.NewCollection()
	table.CreateColumn("name", column.ForString())
	table.CreateColumn("country", column.ForString())
	table.CreateColumn("birthdate", column.ForRecord(func() *time.Time { return new(time.Time) }))
	table.Insert(func(r column.Row) error {
		r.SetString("name", "Charlie")
		r.SetString("country", "Großbritannien")
		r.SetRecord("birthdate", time.Date(1987, 10, 25, 12, 0, 0, 0, time.Local))
		return nil
	})
	srcDate := time.Date(1999, 3, 2, 12, 0, 0, 0, time.Local)
	table.Insert(func(r column.Row) error {
		r.SetString("name", "Alice")
		r.SetString("country", "USA")
		r.SetRecord("birthdate", srcDate)
		return nil
	})
	table.Insert(func(r column.Row) error {
		r.SetString("name", "Alice")
		r.SetString("country", "Österreich")
		r.SetRecord("birthdate", time.Date(1965, 1, 9, 12, 0, 0, 0, time.Local))
		return nil
	})
	table.Insert(func(r column.Row) error {
		r.SetString("name", "Bob")
		r.SetString("country", "Kanada")
		r.SetRecord("birthdate", time.Date(1965, 1, 9, 12, 0, 0, 0, time.Local))
		return nil
	})
	table.Insert(func(r column.Row) error {
		r.SetString("name", "David")
		r.SetString("country", "Australien")
		r.SetRecord("birthdate", time.Date(1978, 3, 4, 12, 0, 0, 0, time.Local))
		return nil
	})
	table.Query(func(txn *column.Txn) error {
		name := txn.String("name")
		country := txn.String("country")
		birthdate := txn.Record("birthdate")
		return txn.WithValue("birthdate", func(v interface{}) bool {
			return v == srcDate // which datatyp should I use here?
		}).Range(func(idx uint32) {
			valueName, _ := name.Get()
			print(" Name: ", valueName)
			valueCountry, _ := country.Get()
			print(" Contry: ", valueCountry)
		        birthdate, _ := birthdate.Get()
			str := fmt.Sprintf("%v", birthdate)
			println(" Birthdate: ", str)
		})
	})
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0