Skip to main content

Simply python library for interact with (EOSIO) WAX blockchain

Project description

Library for interacting with the SQLite database.

Example:

from mwsqlite import MWBase

# create database object (1)
base = MWBase(
    filename="file.db",
    tables={
        "users": {
            "first_name": str,
            "last_name": str,
            "middle_name": str,
            "age": int,
            "info": dict,
            "is_admin": bool,
            "list_rewards": list,
        }
    }
)

# add user to database
base.users.add(
    first_name="John",
    last_name="Doe",
    middle_name="Smith",
    age=18,
    info={"description": "some info"},
    is_admin=False,
    list_rewards=[{"id": 1, "name": "reward1"}, {"id": 2, "name": "reward2"}],
)

# get one user from database
user = base.users.get_one(name="John", age=18)
print(user)
# MWBase.users.Row({'first_name': 'John', 'last_name': 'Doe', 'middle_name': 'Smith', 'age': 18, 'info': {'description': 'some info'}, 'is_admin': False, 'list_rewards': [{'id': 1, 'name': 'reward1'}, {'id': 2, 'name': 'reward2'}]})

base.users.update(
    Where(first_name="John"),
    first_name="Jane",
)

user = base.users.get_one(name="Jane", age=18)
print(user)
#  MWBase.users.Row({'first_name': 'Jane', 'last_name': 'Doe', 'middle_name': 'Smith', 'age': 18, 'info': {'description': 'some info'}, 'is_admin': False, 'list_rewards': [{'id': 1, 'name': 'reward1'}, {'id': 2, 'name': 'reward2'}]})

print(user.age)
# 18
user.update(age=19)
print(user.age)
# 19

user.delete()


user = base.users.get_one(name="Jane", age=18)
print(user)
# None




# get many users from database

for i in range(3):
    base.users.add(first_name="John")

users = base.users.get(name="John")
print(len(users))
# 3

print(users)
# [{'first_name': 'Jane', 'last_name': '', 'age': 0, 'info': {}, 'is_admin': False, 'list_rewards': []}, ...]

TODO:

  • add a way to specify the database name
  • Table class
  • Row class
  • add Table func
  • get Table func
  • update Table func
  • delete Table func
  • update Row func
  • delete Row func
  • get_first Table func
  • get_last Table func
  • get_all Table func
  • MWBase.table("name").get_one(...)
  • clear Table func
  • class Where
  • class Order (ASC, DESC)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mwsqlite-1.0.0.tar.gz (6.6 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page