~amirouche/python-okvs

c1f701a8f155fdafe157f6e92bd576dfa50e079d — Amirouche 11 months ago 93d9538 main
rename size to bytes_count, and count to key_count.
2 files changed, 13 insertions(+), 13 deletions(-)

M okdb/__init__.py
M tests.py
M okdb/__init__.py => okdb/__init__.py +2 -2
@@ 121,7 121,7 @@ def query(cnx, key, other, limit=-1, offset=0):
SQL_QUERY_COUNT = """SELECT COUNT(key) FROM db WHERE key >= ? AND key < ?"""


def count(cnx, key, other):
def key_count(cnx, key, other):
    cursor = cnx.execute(SQL_QUERY_COUNT, (key, other))
    out = cursor.fetchone()[0]
    return out


@@ 130,7 130,7 @@ def count(cnx, key, other):
SQL_QUERY_SIZE = """SELECT SUM(length(key)) + SUM(length(value)) FROM db WHERE key >= ? AND key < ?"""


def size(cnx, key, other):
def bytes_count(cnx, key, other):
    cursor = cnx.execute(SQL_QUERY_SIZE, (key, other))
    out = cursor.fetchone()[0]
    return out

M tests.py => tests.py +11 -11
@@ 85,7 85,7 @@ def test_db_query_limit_offset_desc():
        db.close(cnx)


def test_db_count():
def test_db_key_count():
    with tempfile() as filepath:
        cnx = db.open(filepath)
        expected = [


@@ 95,11 95,11 @@ def test_db_count():
        ]
        for k, v in expected:
            db.set(cnx, k, v)
        assert db.count(cnx, b'\x00', b'\xFF') == 3
        assert db.key_count(cnx, b'\x00', b'\xFF') == 3
        db.close(cnx)


def test_db_size():
def test_db_bytes_count():
    with tempfile() as filepath:
        cnx = db.open(filepath)
        expected = [


@@ 109,11 109,11 @@ def test_db_size():
        ]
        for k, v in expected:
            db.set(cnx, k, v)
        assert db.size(cnx, b'\x00', b'\xFF') == 6
        assert db.bytes_count(cnx, b'\x00', b'\xFF') == 6
        db.close(cnx)


def test_db_count2():
def test_db_key_count2():
    with tempfile() as filepath:
        cnx = db.open(filepath)
        expected = [


@@ 125,11 125,11 @@ def test_db_count2():
        ]
        for k, v in expected:
            db.set(cnx, k, v)
        assert db.count(cnx, b'\x01', b'\xFF') == 3
        assert db.key_count(cnx, b'\x01', b'\xFF') == 3
        db.close(cnx)


def test_db_size2():
def test_db_bytes_count2():
    with tempfile() as filepath:
        cnx = db.open(filepath)
        expected = [


@@ 141,7 141,7 @@ def test_db_size2():
        ]
        for k, v in expected:
            db.set(cnx, k, v)
        assert db.size(cnx, b'\x01', b'\xFF') == 6
        assert db.bytes_count(cnx, b'\x01', b'\xFF') == 6
        db.close(cnx)




@@ 157,15 157,15 @@ def test_db_delete():
        ]
        for k, v in kvs:
            db.set(cnx, k, v)
        assert db.count(cnx, b'\x00', b'\xFF') == 4
        assert db.key_count(cnx, b'\x00', b'\xFF') == 4
        # GIVEN
        db.delete(cnx, b'\x00')
        # THEN
        assert db.count(cnx, b'\x00', b'\xFF') == 3
        assert db.key_count(cnx, b'\x00', b'\xFF') == 3
        # GIVEN
        db.delete(cnx, b'\x00', b'\xFF')
        # THEN
        assert db.count(cnx, b'\x00', b'\xFF') == 0
        assert db.key_count(cnx, b'\x00', b'\xFF') == 0
        db.close(cnx)