Comments (6)
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.
@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.
db.CreateIndex("index_name", "*", buntdb.IndexJSON("product"), buntdb.IndexJSON("level"))
please see https://github.com/tidwall/buntdb#multi-value-index
from buntdb.
@tidwall i see set Multi Value Index,but how can ascend equal this two conditions?
from buntdb.
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.
@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)
- Python bindings
- Enhancement: add new method GetWithTTL to return value together with TTL
- What happens if two funcs write to the db at the exact same time? HOT 1
- Get size of db on disk
- Does the data.db file support rewrite like redis AOF? HOT 2
- Dependencies update due?
- Feature Request: Delete inside iterator
- Question: cost/benefit of supporting generic types; and persisting secondary indexes
- Is it necessary to (defer) db.Close()?
- Expiry works only during runtime and is lost on shrink HOT 1
- index, or getting with different keys doesn't work HOT 1
- tx.Ascend doesn't work correctly HOT 1
- Does buntdb needs Go 1.18+ due to btree dependency? HOT 1
- Question: What is the format of .db file? HOT 1
- I wonder if we can find closest lat long for a given latlon from spatial index using nearby
- [Feature Request] Is there a way to limit memroy usage?
- Is there any plan to support index on MessagePack? HOT 1
- How to renew the ttl?
- Question: Is buntdb goroutine-safe? HOT 1
- Will "group by" be supported in this lib?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from buntdb.