Example #1
0
from autumn.Ipy import Model, DBConnection, Query, Filter, OneToMany, ForeignKey

from alprion import AlprionCfg_

cfg = AlprionCfg_.read('database', ("UID", "PWD"))
cfg['DSN'] = 'AutumnTest'

autumnTestConn = DBConnection(**cfg)

# must drop books first, due to foreign key
autumnTestConn.executeDBNonQuery("truncate books;") 
autumnTestConn.executeDBNonQuery("truncate author;")
autumnTestConn.executeDBNonQuery("truncate transaction;")
print("truncated")

class Author(Model):
    dbconn = DBConnection(**cfg)

    books = OneToMany('Book')
    
class Book(Model):
    dbconn = DBConnection(**cfg)
    
    author = ForeignKey(Author)

    class Meta:
        table = 'books'

class Transaction(Model):
    dbconn = DBConnection(**cfg)
Example #2
0
from autumn import Model, autumn_db, OneToMany, ForeignKey
    
from alprion import AlprionCfg_, PathJoin, DATADIR

dbcfg = AlprionCfg_.read('database', ("marketdb"))
autumn_db.conn.connect('sqlite3', PathJoin(DATADIR, dbcfg['marketdb']))
        
class Instruments(Model):
    class Meta:
        defaults = {'name': 'xxx',
                    'source': 'unkown'}
        
    
class Series(Model):
    class Meta:
        defaults = {'label': 'close'}

  
class Timeseries(Model):
    '''sqlite3: marketdb.db timeseries
        
    '''
    instrument = ForeignKey('Instruments')