-
Notifications
You must be signed in to change notification settings - Fork 0
/
rjdb.py
36 lines (27 loc) · 799 Bytes
/
rjdb.py
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
# coding: utf-8
import os
import sys
from pydblite.pydblite import Base
from workinfo import WorkInfo, FIELDS
class RJDB(object):
def __init__(self):
db = Base('rjdb.pdl')
if db.exists():
db.open()
else:
db.create(*FIELDS)
self.db = db
def insert(self, **kwds):
self.db.insert(**kwds)
def iter_works(self, from_index, to_index):
return (WorkInfo(self).load(r) for i, r in enumerate(self.db) if i >= from_index and i < to_index)
def get_works_count(self):
return len(self.db)
def get_work(self, rj):
records = self.db(rj = rj)
if records:
return WorkInfo(self).load(records[0])
else:
return None
def commit(self):
self.db.commit()