def main(): parser = argparse.ArgumentParser(description='Load data into DB.') parser.add_argument('--file-name', type=str) #parser.add_argument('save-frequency', type=int, default=100) args = parser.parse_args() db = SessionLocal() with open(args.file_name) as f: json_data = json.load(f) objects = [ TextSample(text=str(item), id=str(uuid.uuid4().hex)) for item in json_data['data'] ] db.bulk_save_objects(objects) db.commit()
#!/usr/bin/python3 from app import models from app.db import SessionLocal, engine db = SessionLocal() models.Base.metadata.create_all(bind=engine) account_record = models.Account(accountname='Transaktionskonto Bank', accountnumber=1910) db.add(account_record) account_record = models.Account(accountname='Utgående MOMS 25%', accountnumber=2611) db.add(account_record) account_record = models.Account(accountname='Debiterad ingående MOMS', accountnumber=2641) db.add(account_record) account_record = models.Account(accountname='Försäljning datorer', accountnumber=3010) db.add(account_record) account_record = models.Account(accountname='inköp komponenter', accountnumber=4010) db.add(account_record) db.commit() account_record = db.query(models.Account).filter_by(accountnumber=1910).all() db.close()