本站源代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
2.2KB

  1. // Copyright (c) 2012, Suryandaru Triandana <syndtr@gmail.com>
  2. // All rights reserved.
  3. //
  4. // Use of this source code is governed by a BSD-style license that can be
  5. // found in the LICENSE file.
  6. // Package leveldb provides implementation of LevelDB key/value database.
  7. //
  8. // Create or open a database:
  9. //
  10. // // The returned DB instance is safe for concurrent use. Which mean that all
  11. // // DB's methods may be called concurrently from multiple goroutine.
  12. // db, err := leveldb.OpenFile("path/to/db", nil)
  13. // ...
  14. // defer db.Close()
  15. // ...
  16. //
  17. // Read or modify the database content:
  18. //
  19. // // Remember that the contents of the returned slice should not be modified.
  20. // data, err := db.Get([]byte("key"), nil)
  21. // ...
  22. // err = db.Put([]byte("key"), []byte("value"), nil)
  23. // ...
  24. // err = db.Delete([]byte("key"), nil)
  25. // ...
  26. //
  27. // Iterate over database content:
  28. //
  29. // iter := db.NewIterator(nil, nil)
  30. // for iter.Next() {
  31. // // Remember that the contents of the returned slice should not be modified, and
  32. // // only valid until the next call to Next.
  33. // key := iter.Key()
  34. // value := iter.Value()
  35. // ...
  36. // }
  37. // iter.Release()
  38. // err = iter.Error()
  39. // ...
  40. //
  41. // Iterate over subset of database content with a particular prefix:
  42. // iter := db.NewIterator(util.BytesPrefix([]byte("foo-")), nil)
  43. // for iter.Next() {
  44. // // Use key/value.
  45. // ...
  46. // }
  47. // iter.Release()
  48. // err = iter.Error()
  49. // ...
  50. //
  51. // Seek-then-Iterate:
  52. //
  53. // iter := db.NewIterator(nil, nil)
  54. // for ok := iter.Seek(key); ok; ok = iter.Next() {
  55. // // Use key/value.
  56. // ...
  57. // }
  58. // iter.Release()
  59. // err = iter.Error()
  60. // ...
  61. //
  62. // Iterate over subset of database content:
  63. //
  64. // iter := db.NewIterator(&util.Range{Start: []byte("foo"), Limit: []byte("xoo")}, nil)
  65. // for iter.Next() {
  66. // // Use key/value.
  67. // ...
  68. // }
  69. // iter.Release()
  70. // err = iter.Error()
  71. // ...
  72. //
  73. // Batch writes:
  74. //
  75. // batch := new(leveldb.Batch)
  76. // batch.Put([]byte("foo"), []byte("value"))
  77. // batch.Put([]byte("bar"), []byte("another value"))
  78. // batch.Delete([]byte("baz"))
  79. // err = db.Write(batch, nil)
  80. // ...
  81. //
  82. // Use bloom filter:
  83. //
  84. // o := &opt.Options{
  85. // Filter: filter.NewBloomFilter(10),
  86. // }
  87. // db, err := leveldb.OpenFile("path/to/db", o)
  88. // ...
  89. // defer db.Close()
  90. // ...
  91. package leveldb
上海开阖软件有限公司 沪ICP备12045867号-1