From 74ff0ed3f0b58ad0ce84d5c5380061f28a2e15bb Mon Sep 17 00:00:00 2001 From: SVI Date: Sat, 20 Aug 2022 12:13:22 +0300 Subject: [PATCH 1/2] SVI Formatting README with hints of linter markdown --- README.md | 59 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 113bb1b8..ca560bfa 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,23 @@ +# goLevelDB + This is an implementation of the [LevelDB key/value database](https://github.com/google/leveldb) in the [Go programming language](https://go.dev). [![Build Status](https://app.travis-ci.com/syndtr/goleveldb.svg?branch=master)](https://app.travis-ci.com/syndtr/goleveldb) -Installation ------------ +## Installation - go get github.com/syndtr/goleveldb/leveldb +```bash +go get github.com/syndtr/goleveldb/leveldb +``` -Requirements ------------ +## Requirements -* Need at least `go1.14` or newer. +Need at least `go1.14` or newer. -Usage ------------ +## Usage Create or open a database: + ```go // The returned DB instance is safe for concurrent use. Which mean that all // DB's methods may be called concurrently from multiple goroutine. @@ -24,7 +26,9 @@ db, err := leveldb.OpenFile("path/to/db", nil) defer db.Close() ... ``` + Read or modify the database content: + ```go // Remember that the contents of the returned slice should not be modified. data, err := db.Get([]byte("key"), nil) @@ -36,53 +40,62 @@ err = db.Delete([]byte("key"), nil) ``` Iterate over database content: + ```go iter := db.NewIterator(nil, nil) for iter.Next() { - // Remember that the contents of the returned slice should not be modified, and - // only valid until the next call to Next. - key := iter.Key() - value := iter.Value() - ... + // Remember that the contents of the returned slice should not be modified, and + // only valid until the next call to Next. + key := iter.Key() + value := iter.Value() + ... } iter.Release() err = iter.Error() ... ``` + Seek-then-Iterate: + ```go iter := db.NewIterator(nil, nil) for ok := iter.Seek(key); ok; ok = iter.Next() { - // Use key/value. - ... + // Use key/value. + ... } iter.Release() err = iter.Error() ... ``` + Iterate over subset of database content: + ```go iter := db.NewIterator(&util.Range{Start: []byte("foo"), Limit: []byte("xoo")}, nil) for iter.Next() { - // Use key/value. - ... + // Use key/value. + ... } iter.Release() err = iter.Error() ... ``` + Iterate over subset of database content with a particular prefix: + ```go iter := db.NewIterator(util.BytesPrefix([]byte("foo-")), nil) for iter.Next() { - // Use key/value. - ... + // Use key/value. + .. } iter.Release() err = iter.Error() ... ``` + Batch writes: + ```go batch := new(leveldb.Batch) batch.Put([]byte("foo"), []byte("value")) @@ -91,17 +104,19 @@ batch.Delete([]byte("baz")) err = db.Write(batch, nil) ... ``` + Use bloom filter: + ```go o := &opt.Options{ - Filter: filter.NewBloomFilter(10), + Filter: filter.NewBloomFilter(10), } db, err := leveldb.OpenFile("path/to/db", o) ... defer db.Close() ... ``` -Documentation ------------ + +## Documentation You can read package documentation [here](https://pkg.go.dev/github.com/syndtr/goleveldb). From 542735387c81842e3960ebfc568e3fc01f5f0583 Mon Sep 17 00:00:00 2001 From: SVI Date: Sat, 20 Aug 2022 12:21:56 +0300 Subject: [PATCH 2/2] SVI Add part of russians doc --- README.md | 4 ++ docs/README_ru.md | 123 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+) create mode 100644 docs/README_ru.md diff --git a/README.md b/README.md index ca560bfa..a8dbd79f 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,10 @@ This is an implementation of the [LevelDB key/value database](https://github.com [![Build Status](https://app.travis-ci.com/syndtr/goleveldb.svg?branch=master)](https://app.travis-ci.com/syndtr/goleveldb) +## Other language + +[ru_RU.UTF-8](./docs/README_ru.md) + ## Installation ```bash diff --git a/docs/README_ru.md b/docs/README_ru.md new file mode 100644 index 00000000..c33ebaaa --- /dev/null +++ b/docs/README_ru.md @@ -0,0 +1,123 @@ +# goLevelDB + +Этот проект является реализацией [LevelDB key/value database](https://github.com/google/leveldb) на языке программирования [Go](https://go.dev). + +[![Build Status](https://app.travis-ci.com/syndtr/goleveldb.svg?branch=master)](https://app.travis-ci.com/syndtr/goleveldb) + +## Установка + +```bash +go get github.com/syndtr/goleveldb/leveldb +``` + +## Требования + +Необходим компилятор `go1.14` или новее. + +## Использование + +Cjplfybt yjdjq ,fps lfyys[]: + +```go +// Возвращает новый экземпляр DB, безопасный для конкурентного использования. Which mean that all +// DB's methods may be called concurrently from multiple goroutine. +db, err := leveldb.OpenFile("path/to/db", nil) +... +defer db.Close() +... +``` + +Чтение или изменение содержимого базы данных: + +```go +// Remember that the contents of the returned slice should not be modified. +data, err := db.Get([]byte("key"), nil) +... +err = db.Put([]byte("key"), []byte("value"), nil) +... +err = db.Delete([]byte("key"), nil) +... +``` + +Итерация по содержимому базы данных: + +```go +iter := db.NewIterator(nil, nil) +for iter.Next() { + // Remember that the contents of the returned slice should not be modified, and + // only valid until the next call to Next. + key := iter.Key() + value := iter.Value() + ... +} +iter.Release() +err = iter.Error() +... +``` + +Поиск через итерацию: + +```go +iter := db.NewIterator(nil, nil) +for ok := iter.Seek(key); ok; ok = iter.Next() { + // Use key/value. + ... +} +iter.Release() +err = iter.Error() +... +``` + +Iterate over subset of database content: +Итерация по подмножеству ключей по содержимому базы данных: + +```go +iter := db.NewIterator(&util.Range{Start: []byte("foo"), Limit: []byte("xoo")}, nil) +for iter.Next() { + // Use key/value. + ... +} +iter.Release() +err = iter.Error() +... +``` + +Итерация по подмножеству ключей с указанным префиксом: + +```go +iter := db.NewIterator(util.BytesPrefix([]byte("foo-")), nil) +for iter.Next() { + // Use key/value. + .. +} +iter.Release() +err = iter.Error() +... +``` + +Пакетная запись + +```go +batch := new(leveldb.Batch) +batch.Put([]byte("foo"), []byte("value")) +batch.Put([]byte("bar"), []byte("another value")) +batch.Delete([]byte("baz")) +err = db.Write(batch, nil) +... +``` + +С использованием фильтра Блума: + +```go +o := &opt.Options{ + Filter: filter.NewBloomFilter(10), +} +db, err := leveldb.OpenFile("path/to/db", o) +... +defer db.Close() +... +``` + +## Документация + +Вы можете прочитать документацию [здесь](https://pkg.go.dev/github.com/syndtr/goleveldb).