Compare commits

...

31 Commits

Author SHA1 Message Date
Vincent Batts f6aa21f676 adding a drone build file 2018-07-19 09:11:42 -04:00
Vincent Batts 5b5ff55501
fixing test for updated unqlite
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2017-10-30 22:31:53 -04:00
Vincent Batts 32da34b741
README updates
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2017-10-18 16:19:03 -04:00
Vincent Batts 22e0b9821a
Submodules to latest upstream source
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2017-10-18 15:52:21 -04:00
irieda c965d5c21b Merge pull request #18 from d2g/patch-2
Update Error Messages and Remove unused constant.
2015-03-28 14:07:30 +09:00
unknown 1464c8035f Removed Unused const. 2014-04-08 12:04:04 +01:00
unknown d4f1b96885 Update Error Messages 2014-04-08 12:03:29 +01:00
irieda 75fc045742 Merge pull request #17 from d2g/patch16
Fixes For Issue #16
2014-03-28 17:11:05 +09:00
unknown eb589791cd Fixes For Issue #16 2014-03-17 11:46:13 +00:00
irieda 306fbb4209 Merge pull request #14 from d2g/patch-1
UNQLITE_ENABLE_THREADS=1 On Windows
2014-03-05 09:10:57 +09:00
irieda fa91283ecf Merge pull request #15 from nobonobo/develop
Develop
2014-03-05 09:09:45 +09:00
nobonobo 7f40cedf8d travis fix 2014-03-05 09:03:51 +09:00
nobonobo 0dfcc04c47 travis fix 2014-03-05 09:00:11 +09:00
Dan Goldsmith e350fa2043 UNQLITE_ENABLE_THREADS=1 On Windows
Get it to compile with UNQLITE_ENABLE_THREADS=1 on Windows GCC (On a separate branch this time)
2014-02-25 17:06:19 +00:00
irieda dd85ad5a91 Merge pull request #12 from nobonobo/develop
File Set Fix!
2014-02-05 20:45:43 +09:00
nobonobo e7945470e7 merge 2014-02-05 20:44:00 +09:00
nobonobo 2bf37243a8 merge 2014-02-05 20:42:34 +09:00
nobonobo ef0e8fcbec merge 2014-02-05 20:42:18 +09:00
nobonobo f4ea1cdab8 files fix 2014-02-05 18:01:50 +09:00
irieda a265077155 Merge pull request #10 from nobonobo/develop
別フォルダから利用できなかったのを修正
2013-12-01 21:22:16 -08:00
irieda eaeec8ef44 Update unqlite.go 2013-12-02 14:20:57 +09:00
irieda b5eb549502 Update Makefile 2013-12-02 14:20:29 +09:00
nobonobo af10d52ee0 Merge branch 'release/0.1.4' 2013-11-29 09:05:29 +09:00
nobonobo 1238fa4318 Multiple GOPATH fix 2013-11-29 09:04:50 +09:00
nobonobo 3fc9158a24 Merge branch 'release/0.1.3' 2013-11-28 23:39:06 +09:00
nobonobo f57619c0f1 README fix 2013-11-28 23:38:39 +09:00
nobonobo 825876fd45 Merge branch 'release/0.1.2' 2013-11-28 21:42:20 +09:00
nobonobo 2b0a3e7299 README fix 2013-11-28 21:40:43 +09:00
nobonobo 54d0128c65 Merge branch 'master' of github.com:nobonobo/unqlitego 2013-11-28 21:31:33 +09:00
irieda c93461f0d6 Merge pull request #8 from nobonobo/develop
dependency added
2013-11-26 17:11:40 -08:00
irieda 803591ea8b Merge pull request #7 from nobonobo/develop
fix travis
2013-11-26 17:05:16 -08:00
11 changed files with 135 additions and 59 deletions

6
.drone.yml Normal file
View File

@ -0,0 +1,6 @@
pipeline:
build:
image: golang:1.10
commands:
- go get ./...
- go test ./...

6
.gitmodules vendored
View File

@ -1,3 +1,3 @@
[submodule "src"]
path = src
url = https://github.com/unqlite/unqlite.git
[submodule "unqlite"]
path = unqlite
url = https://github.com/symisc/unqlite.git

View File

@ -2,11 +2,12 @@ language: go
go:
- 1.1
- 1.2
- tip
install:
- go get github.com/r7kamura/gospel
- make install
- go install .
script:
- make test
- go test .

View File

@ -1,25 +0,0 @@
# for GNU make
.PHONY: all build install test clean
all: build
build: libunqlite.a
go build
install: libunqlite.a
go install
clean:
rm -f libunqlite.a
rm -rf src/*
test:
go test ./
src/unqlite.c:
git submodule init
git submodule update
libunqlite.a: src/unqlite.c src/unqlite.h
gcc -c src/unqlite.c -I./src -DUNQLITE_ENABLE_THREADS=1
ar rv libunqlite.a unqlite.o

View File

@ -3,21 +3,34 @@ unqlitego
UnQLite Binding for golang.
[Docs](https://godoc.org/git.thisco.de/vbatts/unqlitego)
Install
---------
```sh
go get -d github.com/nobonobo/unqlitego
cd $GOPATH/src/github.com/nobonobo/unqlitego
git submodule init
git submodule update
make
go install
$ go get git.thisco.de/vbatts/unqlitego
```
Test
---------
```sh
$ go get github.com/r7kamura/gospel
$ cd ${GOPATH/:*/}/src/git.thisco.de/vbatts/unqlitego
$ go test .
```
Benchmark
----------
```sh
$ go get github.com/r7kamura/gospel
$ cd ${GOPATH/:*/}/src/git.thisco.de/vbatts/unqlitego
$ go test -bench Bench*
```
Output:(Macbook Air 2011 mid)
```
BenchmarkFileStore 200000 9667 ns/op
BenchmarkFileFetch 500000 7928 ns/op

1
src

@ -1 +0,0 @@
Subproject commit 480271123692090441b41c54d0433218d592da15

1
unqlite Submodule

@ -0,0 +1 @@
Subproject commit ca65e2b9f690c7609bd0d062c142479b53074bd5

1
unqlite.c Symbolic link
View File

@ -0,0 +1 @@
unqlite/unqlite.c

View File

@ -1,8 +1,10 @@
package unqlitego
/*
#cgo LDFLAGS: -L./ -lunqlite
#include "./src/unqlite.h"
#cgo linux CFLAGS: -DUNQLITE_ENABLE_THREADS=1 -Wno-unused-but-set-variable
#cgo darwin CFLAGS: -DUNQLITE_ENABLE_THREADS=1
#cgo windows CFLAGS: -DUNQLITE_ENABLE_THREADS=1
#include "./unqlite.h"
#include <stdlib.h>
*/
import "C"
@ -24,13 +26,30 @@ func (e UnQLiteError) Error() string {
return s
}
const (
// UnQLiteNoMemErr ...
UnQLiteNoMemErr UnQLiteError = UnQLiteError(C.UNQLITE_NOMEM)
)
var errString = map[UnQLiteError]string{
C.UNQLITE_NOMEM: "Out of memory",
C.UNQLITE_LOCKERR: "Locking protocol error",
C.UNQLITE_READ_ONLY: "Read only Key/Value storage engine",
C.UNQLITE_CANTOPEN: "Unable to open the database file",
C.UNQLITE_FULL: "Full database",
C.UNQLITE_VM_ERR: "Virtual machine error",
C.UNQLITE_COMPILE_ERR: "Compilation error",
C.UNQLITE_DONE: "Operation done", // Not an error.
C.UNQLITE_CORRUPT: "Corrupt pointer",
C.UNQLITE_NOOP: "No such method",
C.UNQLITE_PERM: "Permission error",
C.UNQLITE_EOF: "End Of Input",
C.UNQLITE_NOTIMPLEMENTED: "Method not implemented by the underlying Key/Value storage engine",
C.UNQLITE_BUSY: "The database file is locked",
C.UNQLITE_UNKNOWN: "Unknown configuration option",
C.UNQLITE_EXISTS: "Record exists",
C.UNQLITE_ABORT: "Another thread have released this instance",
C.UNQLITE_INVALID: "Invalid parameter",
C.UNQLITE_LIMIT: "Database limit reached",
C.UNQLITE_NOTFOUND: "No such record",
C.UNQLITE_LOCKED: "Forbidden Operation",
C.UNQLITE_EMPTY: "Empty record",
C.UNQLITE_IOERR: "IO error",
C.UNQLITE_NOMEM: "Out of memory",
}
// Database ...
@ -80,9 +99,19 @@ func (db *Database) Close() (err error) {
// Store ...
func (db *Database) Store(key, value []byte) (err error) {
var k, v unsafe.Pointer
if len(key) > 0 {
k = unsafe.Pointer(&key[0])
}
if len(value) > 0 {
v = unsafe.Pointer(&value[0])
}
res := C.unqlite_kv_store(db.handle,
unsafe.Pointer(&key[0]), C.int(len(key)),
unsafe.Pointer(&value[0]), C.unqlite_int64(len(value)))
k, C.int(len(key)),
v, C.unqlite_int64(len(value)))
if res == C.UNQLITE_OK {
return nil
}
@ -91,9 +120,19 @@ func (db *Database) Store(key, value []byte) (err error) {
// Append ...
func (db *Database) Append(key, value []byte) (err error) {
var k, v unsafe.Pointer
if len(key) > 0 {
k = unsafe.Pointer(&key[0])
}
if len(value) > 0 {
v = unsafe.Pointer(&value[0])
}
res := C.unqlite_kv_append(db.handle,
unsafe.Pointer(&key[0]), C.int(len(key)),
unsafe.Pointer(&value[0]), C.unqlite_int64(len(value)))
k, C.int(len(key)),
v, C.unqlite_int64(len(value)))
if res != C.UNQLITE_OK {
err = UnQLiteError(res)
}
@ -102,14 +141,20 @@ func (db *Database) Append(key, value []byte) (err error) {
// Fetch ...
func (db *Database) Fetch(key []byte) (value []byte, err error) {
var k unsafe.Pointer
if len(key) > 0 {
k = unsafe.Pointer(&key[0])
}
var n C.unqlite_int64
res := C.unqlite_kv_fetch(db.handle, unsafe.Pointer(&key[0]), C.int(len(key)), nil, &n)
res := C.unqlite_kv_fetch(db.handle, k, C.int(len(key)), nil, &n)
if res != C.UNQLITE_OK {
err = UnQLiteError(res)
return
}
value = make([]byte, int(n))
res = C.unqlite_kv_fetch(db.handle, unsafe.Pointer(&key[0]), C.int(len(key)), unsafe.Pointer(&value[0]), &n)
res = C.unqlite_kv_fetch(db.handle, k, C.int(len(key)), unsafe.Pointer(&value[0]), &n)
if res != C.UNQLITE_OK {
err = UnQLiteError(res)
}
@ -118,7 +163,13 @@ func (db *Database) Fetch(key []byte) (value []byte, err error) {
// Delete ...
func (db *Database) Delete(key []byte) (err error) {
res := C.unqlite_kv_delete(db.handle, unsafe.Pointer(&key[0]), C.int(len(key)))
var k unsafe.Pointer
if len(key) > 0 {
k = unsafe.Pointer(&key[0])
}
res := C.unqlite_kv_delete(db.handle, k, C.int(len(key)))
if res != C.UNQLITE_OK {
err = UnQLiteError(res)
}
@ -177,7 +228,13 @@ func (curs *Cursor) Close() (err error) {
// Seek ...
func (curs *Cursor) Seek(key []byte) (err error) {
res := C.unqlite_kv_cursor_seek(curs.handle, unsafe.Pointer(&key[0]), C.int(len(key)), C.UNQLITE_CURSOR_MATCH_EXACT)
var k unsafe.Pointer
if len(key) > 0 {
k = unsafe.Pointer(&key[0])
}
res := C.unqlite_kv_cursor_seek(curs.handle, k, C.int(len(key)), C.UNQLITE_CURSOR_MATCH_EXACT)
if res != C.UNQLITE_OK {
err = UnQLiteError(res)
}
@ -186,7 +243,13 @@ func (curs *Cursor) Seek(key []byte) (err error) {
// SeekLE ...
func (curs *Cursor) SeekLE(key []byte) (err error) {
res := C.unqlite_kv_cursor_seek(curs.handle, unsafe.Pointer(&key[0]), C.int(len(key)), C.UNQLITE_CURSOR_MATCH_LE)
var k unsafe.Pointer
if len(key) > 0 {
k = unsafe.Pointer(&key[0])
}
res := C.unqlite_kv_cursor_seek(curs.handle, k, C.int(len(key)), C.UNQLITE_CURSOR_MATCH_LE)
if res != C.UNQLITE_OK {
err = UnQLiteError(res)
}
@ -195,7 +258,13 @@ func (curs *Cursor) SeekLE(key []byte) (err error) {
// SeekGE ...
func (curs *Cursor) SeekGE(key []byte) (err error) {
res := C.unqlite_kv_cursor_seek(curs.handle, unsafe.Pointer(&key[0]), C.int(len(key)), C.UNQLITE_CURSOR_MATCH_GE)
var k unsafe.Pointer
if len(key) > 0 {
k = unsafe.Pointer(&key[0])
}
res := C.unqlite_kv_cursor_seek(curs.handle, k, C.int(len(key)), C.UNQLITE_CURSOR_MATCH_GE)
if res != C.UNQLITE_OK {
err = UnQLiteError(res)
}

1
unqlite.h Symbolic link
View File

@ -0,0 +1 @@
unqlite/unqlite.h

View File

@ -3,9 +3,10 @@ package unqlitego
import (
"bytes"
"fmt"
. "github.com/r7kamura/gospel"
"io/ioutil"
"testing"
. "github.com/r7kamura/gospel"
)
func Testライブラリ(t *testing.T) {
@ -15,16 +16,16 @@ func Testライブラリ(t *testing.T) {
Expect(IsThreadSafe()).To(Equal, true)
})
It("Version", func() {
Expect(Version()).To(Equal, "1.1.6")
Expect(Version()).To(Equal, "1.1.7")
})
It("Signature", func() {
Expect(Signature()).To(Equal, "unqlite/1.1.6")
Expect(Signature()).To(Equal, "unqlite/1.1.7")
})
It("Ident", func() {
Expect(Ident()).To(Equal, "unqlite:b172a1e2c3f62fb35c8e1fb2795121f82356cad6")
})
It("Copyright", func() {
Expect(Copyright()).To(Equal, "Copyright (C) Symisc Systems, S.U.A.R.L [Mrad Chems Eddine <chm@symisc.net>] 2012-2013, http://unqlite.org/")
Expect(Copyright()).To(Equal, `Copyright (C) Symisc Systems, S.U.A.R.L [Mrad Chems Eddine <chm@symisc.net>] 2012-2016, http://unqlite.org/`)
})
})
})
@ -54,11 +55,20 @@ func Testモジュール(t *testing.T) {
err := db.Store([]byte("sample"), src)
Expect(err).To(NotExist)
})
It("Database.Store.ZeroByte", func() {
err := db.Store([]byte{}, src)
Expect(err).To(Exist)
})
It("Database.Fetch", func() {
dst, err := db.Fetch([]byte("sample"))
Expect(err).To(NotExist)
Expect(bytes.Compare(src, dst)).To(Equal, 0)
})
It("Database.Fetch.ZeroByte", func() {
value, err := db.Fetch([]byte{})
Expect(err).To(Exist)
Expect(value).To(NotExist)
})
It("Database.Append", func() {
err1 := db.Append([]byte("sample"), []byte(" append"))
Expect(err1).To(NotExist)