X-Git-Url: http://dolda2000.com/gitweb/?p=didex.git;a=blobdiff_plain;f=didex%2Findex.py;h=ff291b2db1589b9c52b711f3c04cce4d87261ad2;hp=c2c55b6cfd3eec2921b588c0786052367bde69b9;hb=bd776ebde23c751118effd893d3e1529dfbbf23c;hpb=f9b1d04098f80bf065480c94975996b87c820da7 diff --git a/didex/index.py b/didex/index.py index c2c55b6..ff291b2 100644 --- a/didex/index.py +++ b/didex/index.py @@ -2,7 +2,7 @@ import struct, contextlib, math from . import db, lib from .db import bd, txnfun, dloopfun -__all__ = ["maybe", "t_int", "t_uint", "t_dbid", "t_float", "t_str", "t_casestr", "ordered"] +__all__ = ["maybe", "t_bool", "t_int", "t_uint", "t_dbid", "t_float", "t_str", "t_casestr", "ordered"] deadlock = bd.DBLockDeadlockError notfound = bd.DBNotFoundError @@ -140,6 +140,7 @@ def floatcmp(a, b): else: return 0 +t_bool = simpletype((lambda ob: b"\x01" if ob else b"\x00"), (lambda dat: False if dat == b"x\00" else True)) t_int = simpletype.struct(">q") t_uint = simpletype.struct(">Q") t_dbid = t_uint @@ -158,9 +159,9 @@ class index(object): missing = object() class ordered(index, lib.closable): - def __init__(self, db, name, datatype, create=True): + def __init__(self, db, name, datatype, create=True, *, tx=None): super().__init__(db, name, datatype) - fl = bd.DB_THREAD | bd.DB_AUTO_COMMIT + fl = bd.DB_THREAD if create: fl |= bd.DB_CREATE def initdb(db): def compare(a, b): @@ -168,7 +169,7 @@ class ordered(index, lib.closable): return self.typ.compare(self.typ.decode(a), self.typ.decode(b)) db.set_flags(bd.DB_DUPSORT) db.set_bt_compare(compare) - self.bk = db._opendb("i-" + name, bd.DB_BTREE, fl, initdb) + self.bk = db._opendb("i-" + name, bd.DB_BTREE, fl, initdb, tx=tx) self.bk.set_get_returns_none(False) def close(self):