def create_schema(db, table_name, table_schema):
     table = Table(table_name, db)
     if len(table.info()) is 0:
         table.create(*table_schema)
     else:
         table.open()
     return table
示例#2
0
class DBConnect(object):
    """[configure pydblite db connection]
    
    Arguments:
        object {[Object]} -- [description]
    """

    db = Database('grading_app_db', check_same_thread=False)

    students_table = Table("Students", db)
    assignments_table = Table("Assignments", db)
    questions_table = Table("Questions", db)
    grades_table = Table("Grades", db)
    assignments_students_table = Table("Assignments_Students", db)

    db.conn.text_factory = str

    def __init__(self):
        self.students_table.create(('id', 'TEXT'), ('name', 'TEXT'),
                                   mode="open")

        self.assignments_table.create(
            ('id', 'TEXT'), ('name', 'TEXT'), ('grade_details_01', 'TEXT'),
            ('grade_details_02', 'TEXT'), ('grade_details_03', 'TEXT'),
            ('grade_details_04', 'TEXT'), ('pass_mark', 'INTEGER'),
            mode="open")

        self.questions_table.create(
            ('id', 'TEXT'), ('assignmentId', 'TEXT'), ('question', 'TEXT'),
            ('answer_01', 'TEXT'), ('answer_02', 'TEXT'),
            ('answer_03', 'TEXT'), ('answer_04', 'TEXT'),
            ('correct_answer', 'TEXT'), ('marks', 'INTEGER'),
            mode="open")

        self.grades_table.create(
            ('id', 'TEXT'), ('studentId', 'TEXT'), ('assignmentId', 'TEXT'),
            ('questionId', 'TEXT'), ('timeSpent', 'REAL'), ('answer', 'TEXT'),
            ('marks', 'INTEGER'),
            mode="open")

        self.assignments_students_table.create(
            ('id', 'TEXT'), ('assignmentId', 'TEXT'), ('studentId', 'TEXT'),
            mode="open")
class DBConnect(object):
    """[configure pydblite db connection]
    
    Arguments:
        object {[Object]} -- [description]
    """

    db = Database('treatment_app_db', check_same_thread=False)

    predictions_table = Table("Predictions", db)

    db.conn.text_factory = str

    def __init__(self):
        self.predictions_table.create(
            ('id', 'TEXT'),
            ('name', 'TEXT'),
            ('age', 'INTEGER'),
            ('gender', 'INTEGER'),
            ('brushingTeeth', 'INTEGER'),
            ('dailyFlossing', 'INTEGER'),
            ('betelChewing', 'INTEGER'),
            ('betelWithTobacco', 'INTEGER'),
            ('alcoholConsumption', 'INTEGER'),
            ('smoking', 'INTEGER'),
            ('cariousTeeth', 'INTEGER'),
            ('gumDisease', 'INTEGER'),
            ('bleedingWhileBrushing', 'INTEGER'),
            ('depositsTartar', 'INTEGER'),
            ('accidentalFracture', 'INTEGER'),
            ('missingTeeth', 'INTEGER'),
            ('stainsOnTeeth', 'INTEGER'),
            ('malalignedTeeth', 'INTEGER'),
            ('toothache', 'INTEGER'),
            ('facialPain', 'INTEGER'),
            ('headache', 'INTEGER'),
            ('nightPain', 'INTEGER'),
            ('painWhileBiting', 'INTEGER'),
            ('swollenCheek', 'INTEGER'),
            ('painFromAnUlcer', 'INTEGER'),
            ('swellingWithPain', 'INTEGER'),
            ('swellingWithoutPain', 'INTEGER'),
            ('clickingSoundWhileOpening', 'INTEGER'),
            ('sensitiveToHotBeverages', 'INTEGER'),
            ('sensitiveToColdBeverages', 'INTEGER'),
            ('adultUpperJawDecayed', 'INTEGER'),
            ('adultUpperJawMissing', 'INTEGER'),
            ('adultUpperJawFilled', 'INTEGER'),
            ('adultLowerJawDecayed', 'INTEGER'),
            ('adultLowerJawMissing', 'INTEGER'),
            ('adultLowerJawFilled', 'INTEGER'),
            ('treatment', 'TEXT'),
             mode="open" )
示例#4
0
ENABLE_REDIS = True
PROXY = True

ROOM_ID_LEN = 5
ID_RANGE = string.digits

MAX_ROOM_SIZE = 10

MAX_NUM_OF_RECORDS = {'users': 500, 'rooms': 500}
REQUEST_LIMIT = {'create': '10/minute', 'room': '2/second'}

words_500 = Corpus('corpora/words-500.txt', wsgi=False)

db = Database('WhoIsTheSpy.sqlite')

users = Table('users', db)
rooms = Table('rooms', db)

if 'users' not in db:

    users.create(('uuid', 'TEXT'), ('room', 'TEXT'),
                 ('num', 'INTEGER'))
    users.create_index('uuid')

if 'rooms' not in db:

    rooms.create(('room', 'TEXT'), ('civ_word', 'TEXT'),
                 ('spy_word', 'TEXT'), ('spy_num', 'INTEGER'),
                 ('total', 'INTEGER'), ('count', 'INTEGER'),
                 ('start', 'INTEGER'))
    rooms.create_index('room')
示例#5
0
def sqlite():
    from pydblite.sqlite import Database, Table
    # connect to SQLite database "test"
    db = Database(":memory:")
    # pass the table name and database path as arguments to Table creation
    table = Table('dummy', db)
    # create new base with field names
    table.create(('name', 'TEXT'), ('age', 'INTEGER'), ('size', 'REAL'))
    # existing base
    table.open()
    # insert new record
    table.insert(name='homer', age=23, size=1.84)
    table.insert(name='marge', age=36, size=1.94)
    rec_id = table.insert(name='Lisa', age=13, size=1.24)

    # records are dictionaries with a unique integer key __id__
    # selection by list comprehension
    res = [r for r in table if 30 > r['age'] >= 18 and r['size'] < 2]
    print("res:", res)
    # or generator expression
    for r in (r for r in table if r['name'] in ('homer', 'marge')):
        pass
    # simple selection (equality test)
    records = table(age=23)

    # delete a record by its id
    del table[rec_id]

    rec_id = records[0]['__id__']

    # direct access by id
    record = table[rec_id]  # the record such that record['__id__'] == rec_id
    # update
    table.update(record, age=24)
    # add a field
    table.add_field('new_field')  # Defaults to type 'TEXT'
    # save changes on disk
    table.commit()