This repository has been archived by the owner on Jan 18, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathproto.go
78 lines (64 loc) · 2.22 KB
/
proto.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package orient
// Default protocols
const (
ProtoBinary = "binary"
)
// DatabaseType defines database access type (Document or Graph)
type DatabaseType string
// List of database access types
const (
DocumentDB DatabaseType = "document"
GraphDB DatabaseType = "graph"
)
// StorageType defines supported database storage types
type StorageType string
const (
// Persistent type represents on-disk database
Persistent StorageType = "plocal"
// Volatile type represents in-memory database
Volatile StorageType = "memory"
)
var (
protos = make(map[string]func(addr string) (DBConnection, error))
)
// RegisterProto registers a new protocol for Dial command
func RegisterProto(name string, dial func(addr string) (DBConnection, error)) {
protos[name] = dial
}
// ODatabase stores database metadata
type ODatabase struct {
Name string
Type DatabaseType
Classes map[string]*OClass
}
// DBAdmin is a minimal interface for database management API implementation
type DBAdmin interface {
DatabaseExists(name string, storageType StorageType) (bool, error)
CreateDatabase(name string, dbType DatabaseType, storageType StorageType) error
DropDatabase(name string, storageType StorageType) error
ListDatabases() (map[string]string, error)
Close() error
}
// DBSession is a minimal interface for database API implementation
type DBSession interface {
Close() error
Size() (int64, error)
ReloadSchema() error
GetCurDB() *ODatabase
AddClusterWithID(clusterName string, id int16) (clusterID int16, err error)
DropCluster(clusterName string) (err error)
GetClusterDataRange(clusterName string) (begin, end int64, err error)
ClustersCount(withDeleted bool, clusterNames ...string) (int64, error)
CreateRecord(rec ORecord) (err error)
DeleteRecordByRID(rid RID, recVersion int) error
GetRecordByRID(rid RID, fetchPlan FetchPlan, ignoreCache bool) (rec ORecord, err error)
UpdateRecord(rec ORecord) error
CountRecords() (int64, error)
Command(cmd CustomSerializable) (result interface{}, err error)
}
// DBConnection is a minimal interface for OrientDB server API implementation
type DBConnection interface {
Auth(user, pass string) (DBAdmin, error)
Open(name string, dbType DatabaseType, user, pass string) (DBSession, error)
Close() error
}