Giter Site home page Giter Site logo

pycopy-btreedb's Introduction

pycopy-btreedb's People

Contributors

pfalcon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

pycopy-btreedb's Issues

Example, docs ?

Hi,

The project sounds interesting and I am trying to make it work for my uses (esp32).
However, even if code is simple, reverse eng. isn't very fun :)

Do you have a little example or doc stub for this package ?

Thanks,
Jonathan

Example use

from . import db
from .db import EasyDB

db.db.connect()

db.EasyDB.create_table()

upy_id = db.EasyDB.create(test=1)
upy_id = db.EasyDB.create(test=2)
upy_id = db.EasyDB.create(test=3)

pkey='2017-09-26 00:04:34'
db.EasyDB.delete({"timestamp": pkey})

pkey='2017-09-26 00:06:54'
upy_id = db.EasyDB.get_id(pkey)

upy_id = db.EasyDB.select(test=1)
print(list(upy_id))

upy_id = db.EasyDB.scan()
print(list(upy_id))

db.db.close()

Example use: EasyDB

from ucollections import OrderedDict
import ujson
import utime

import btreedb as uorm
import btree

db = uorm.DB("test.db")

class EasyDB(uorm.Model):

# Create controller table
__db__ = db
__table__ = "testtable"
__schema__ = OrderedDict([
    ("timestamp", ("TIMESTAMP", uorm.now)),
    ("test", ("INT", 0)),
])

Example

From an ex-Oracle girl:

  • Two additonal functions: Delete and Select
  • Example ('example use' and 'example use: easydb', save the latter as db.py)
    It's almost Oracle now... ;-)

Additional functions: Delete and Select

@classmethod
def delete(cls, where, **fields):
    pkey_field = cls.__fields__[0]
    assert len(where) == 1 and pkey_field in where
    #print("update:", where)

    db = cls.__db__.db
    pkey = where[pkey_field]
    del(db[pkey])
    db.flush()

@classmethod
def select(cls, **fields):
    for v in cls.__db__.db.values():
        row = cls.Row(*ujson.loads(v))
        i = 0
        for k in cls.__fields__:
            if k in fields:
               if row[i] == fields[k]:
                  yield row
            i += 1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.