Beispiel #1
0
    def open_session(self):
        """Open a new database session.

        Uses default values for any not stored in the local settings.json file.
        """
        json  = settings.load(subdir=u'database')
        json.setdefault('name', u'admin')
        json.setdefault('pw', u'admin')
        json.setdefault('api', u'mysql+pymysql')
        json.setdefault('ip', u'000.0.0.000')
        json.setdefault('opt', u'?charset=utf8')
        json.setdefault('port', u':3306')
        json.setdefault('db', u'taimau')

        self.dbpath = u"{ip}{port}/{db}".format(**json)

        db_path = u"{api}://{name}:{pw}@{ip}{port}/{db}{opt}"
        db_path = db_path.format(**json)

        engine = get_database(db_path,  echo=False )
        self.session = sessionmaker(bind=engine)()
Beispiel #2
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from sqlalchemy.orm import sessionmaker
import db_manager as DM # v2 manager
import datetime
import random
from TM2014_tables_v3 import get_database, CoGroup, Branch, Product, Contact, Stock, Order, Shipment, ShipmentItem, Invoice, InvoiceItem, Vehicle


dbname = r"C:\Users\Jay\Dropbox\GitHub\TAIMAU\src\TM2014_v3.db"
database = get_database(dbname)
newsession = sessionmaker(bind=database)()

#TODO: Still needs testing in the program to make sure all records appear normal

#===============================================================================
# MIGRATE COMPANIES AND PRODUCTS AND ASSETS

added = set()
for i, rec in enumerate(DM.session.query(DM.CoGroup)):
    rec = rec.__dict__
    if i==0:
        print "CoGroup -----------------------------------------"
        for each in rec.keys():
            print each
    del rec['_sa_instance_state']
    del rec['branches']
#    print ">", rec

    newsession.add(CoGroup(**rec))