2015-07-26 16:33:29 +02:00
|
|
|
// Copyright 2014, 2015 by Sascha L. Teichmann
|
2014-08-03 15:59:56 +02:00
|
|
|
// Use of this source code is governed by the MIT license
|
|
|
|
// that can be found in the LICENSE file.
|
|
|
|
|
2014-08-03 11:25:25 +02:00
|
|
|
package main
|
|
|
|
|
2014-08-19 11:11:41 +02:00
|
|
|
type (
|
2024-01-07 10:54:21 +01:00
|
|
|
// block is the essential transfer unit from to the database.
|
2016-04-24 19:41:15 +02:00
|
|
|
// Key is the serialized spatial position.
|
|
|
|
// Data is the serialized from of the corresponding block data.
|
2024-01-07 10:54:21 +01:00
|
|
|
block struct {
|
2014-09-01 00:19:47 +02:00
|
|
|
Key []byte
|
|
|
|
Data []byte
|
|
|
|
}
|
|
|
|
|
2024-01-07 10:54:21 +01:00
|
|
|
// session is a database session.
|
|
|
|
session interface {
|
|
|
|
// del deletes a block by a given key.
|
|
|
|
del(hash, key []byte) (bool, error)
|
|
|
|
// fetch fetches the block data for a given position.
|
|
|
|
fetch(hash, key []byte) ([]byte, error)
|
|
|
|
// inTransaction returns true if a transaction is running.
|
|
|
|
inTransaction() bool
|
|
|
|
// store stores a block with a given position and data.
|
|
|
|
store(hash, key, value []byte) (bool, error)
|
|
|
|
// allKeys returns all keys in the database.
|
|
|
|
allKeys(hash []byte, done <-chan struct{}) (<-chan []byte, int, error)
|
|
|
|
// spatialQuery performs a box query between the positions first and second.
|
|
|
|
spatialQuery(hash, first, second []byte, done <-chan struct{}) (<-chan block, error)
|
|
|
|
// beginTransaction starts a transcation.
|
|
|
|
beginTransaction() error
|
|
|
|
// commitTransaction finishes a transaction.
|
|
|
|
commitTransaction() error
|
|
|
|
// close closes the database session.
|
|
|
|
close() error
|
2014-08-19 11:11:41 +02:00
|
|
|
}
|
2014-08-06 01:11:41 +02:00
|
|
|
|
2024-01-07 10:54:21 +01:00
|
|
|
// backend is the interface representing a database.
|
|
|
|
backend interface {
|
|
|
|
// newSession opens a new session.
|
|
|
|
newSession() (session, error)
|
|
|
|
// shutdown shuts down the database server.
|
|
|
|
shutdown() error
|
2014-08-19 11:11:41 +02:00
|
|
|
}
|
|
|
|
)
|