Coder Social home page Coder Social logo

Comments (6)

tidwall avatar tidwall commented on May 16, 2024

Indexes can only be assigned to values. You cannot add an index to a key. The key is always ordered by it's binary value.

You will need to format your timestamp so it's sortable.

For example:

 2017-09-11T10:35:21.9082
 2017-09-11T10:35:28.8293
 2017-09-12T08:05:13.0012

Or if you want to make the best use of space you can store the nanoseconds representation an int64 or time.Time.

The following serializes a time.Time object into an 8 byte key with nanosecond precision.

key := make([]byte, 8)
binary.LittleEndian.PutUint64(key, timestamp.UnixNano())

Then add the key/value to the database.

tx.Set(string(key), "some value", nil)

from buntdb.

jjjachyty avatar jjjachyty commented on May 16, 2024

@tidwall i want use Multi Value Index with json,like this {"product":"RPM","level":"2"} ,i want equal this pattern ,how todo it?

from buntdb.

tidwall avatar tidwall commented on May 16, 2024
db.CreateIndex("index_name", "*", buntdb.IndexJSON("product"), buntdb.IndexJSON("level"))

please see https://github.com/tidwall/buntdb#multi-value-index

from buntdb.

jjjachyty avatar jjjachyty commented on May 16, 2024

@tidwall i see set Multi Value Index,but how can ascend equal this two conditions?

from buntdb.

tidwall avatar tidwall commented on May 16, 2024

See #18 for an example of how to ascend specialized JSON queries.
Please attach any code that you've tried and I'll do my best to help diagnose the issue.

from buntdb.

jjjachyty avatar jjjachyty commented on May 16, 2024

@tidwall I'm very sorry ,I have a lot of questions,Thank you for your answer patiently。
i have this data

*3
$3
set
$10
1502867961
$357
{
    "product": "RPM",
    "level": "6",
    "modular": "DP",
    "event": "1",
    "origValue": "",
    "currentValue": "测试",
    "operatorKey": "9527",
    "operatorAt":1502676101,
    "operatorName": "周星星",
    "operatorIP": "172.168.171.252",
    "operatorClient": "1",
    "sqlSentence": "select * from dual",
    "sqlParameter": "[1,2,3]"
}
*3
$3
set
$10
1502867965
$357
{
    "product": "RPM",
    "level": "5",
    "modular": "DP",
    "event": "1",
    "origValue": "",
    "currentValue": "测试",
    "operatorKey": "9527",
    "operatorAt":1502676102,
    "operatorName": "周星星",
    "operatorIP": "172.168.171.252",
    "operatorClient": "1",
    "sqlSentence": "select * from dual",
    "sqlParameter": "[1,2,3]"
}
*3
$3
set
$10
1502867971
$357
{
    "product": "RPM",
    "level": "4",
    "modular": "DP",
    "event": "1",
    "origValue": "",
    "currentValue": "测试",
    "operatorKey": "9527",
    "operatorAt":1502676103,
    "operatorName": "周星星",
    "operatorIP": "172.168.171.252",
    "operatorClient": "1",
    "sqlSentence": "select * from dual",
    "sqlParameter": "[1,2,3]"
}
*3
$3
set
$10
1502867975
$357
{
    "product": "RPM",
    "level": "3",
    "modular": "DP",
    "event": "1",
    "origValue": "",
    "currentValue": "测试",
    "operatorKey": "9527",
    "operatorAt":1502676104,
    "operatorName": "周星星",
    "operatorIP": "172.168.171.252",
    "operatorClient": "1",
    "sqlSentence": "select * from dual",
    "sqlParameter": "[1,2,3]"
}
*3
$3
set
$10
1502867982
$357
{
    "product": "RPM",
    "level": "2",
    "modular": "DP",
    "event": "1",
    "origValue": "",
    "currentValue": "测试",
    "operatorKey": "9527",
    "operatorAt":1502676105,
    "operatorName": "周星星",
    "operatorIP": "172.168.171.252",
    "operatorClient": "1",
    "sqlSentence": "select * from dual",
    "sqlParameter": "[1,2,3]"
}
*3
$3
set
$10
1502867987
$357
{
    "product": "RPM",
    "level": "1",
    "modular": "DP",
    "event": "1",
    "origValue": "",
    "currentValue": "测试",
    "operatorKey": "9527",
    "operatorAt":1502676106,
    "operatorName": "周星星",
    "operatorIP": "172.168.171.252",
    "operatorClient": "1",
    "sqlSentence": "select * from dual",
    "sqlParameter": "[1,2,3]"
}

i want to query use product&level&modular&event fields and use operatorAt field Descending order

db.BuntdbDB.CreateIndex("buntdb", "*", buntdb.IndexJSON("level"),buntdb.Desc(buntdb.IndexJSON("operatorAt")))

	err := db.BuntdbDB.View(func(tx *buntdb.Tx) error {
		err := tx.DescendGreaterThan("buntdb", {"level":"3"}, func(key, value string) bool {
				fmt.Println("\n\n\n", key, value, "\n\n\n")
			return true
		})

		return err
	})

output:

[{
    "product": "RPM",
    "level": "6",
    "modular": "DP",
    "event": "1",
    "origValue": "",
    "currentValue": "测试",
    "operatorKey": "9527",
    "operatorAt":1502676101,
    "operatorName": "周星星",
    "operatorIP": "172.168.171.252",
    "operatorClient": "1",
    "sqlSentence": "select * from dual",
    "sqlParameter": "[1,2,3]"
},{
    "product": "RPM",
    "level": "5",
    "modular": "DP",
    "event": "1",
    "origValue": "",
    "currentValue": "测试",
    "operatorKey": "9527",
    "operatorAt":1502676102,
    "operatorName": "周星星",
    "operatorIP": "172.168.171.252",
    "operatorClient": "1",
    "sqlSentence": "select * from dual",
    "sqlParameter": "[1,2,3]"
}{
    "product": "RPM",
    "level": "4",
    "modular": "DP",
    "event": "1",
    "origValue": "",
    "currentValue": "测试",
    "operatorKey": "9527",
    "operatorAt":1502676103,
    "operatorName": "周星星",
    "operatorIP": "172.168.171.252",
    "operatorClient": "1",
    "sqlSentence": "select * from dual",
    "sqlParameter": "[1,2,3]"
}]

Not descending by operatorAt

from buntdb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.