Replies: 1 comment 1 reply
-
If you're using ORM then a better approach is using Here is an example of using class Patient(db.Model):
id = db.Column(db.Integer, primary_key=True)
email = db.Column(db.String(120), unique=True)
phone_number = db.Column(db.String(25))
full_name = db.Column(db.String(100))
weight = db.Column(db.String(64))
height = db.Column(db.String(64))
blood_type = db.Column(db.String(64))
def __init__(self, **kwargs):
super(Patient, self).__init__(**kwargs)
@staticmethod
def _bootstrap(count=2000, locale='en'):
from mimesis import Generic
from mimesis.locale import Locale
generic = Generic(Locale.FR)
for _ in range(count):
patient = Patient(
email=generic.person.email(),
phone_number=generic.person.telephone(),
full_name=generic.person.full_name(gender='female'),
weight=generic.person.weight(),
height=generic.person.height(),
blood_type=generic.person.blood_type()
)
db.session.add(patient)
try:
db.session.commit()
except Exception:
db.session.rollback() It's better to store code from I hope, I explained the idea well. Anyway, if you don't get it then don't be shy to ask me — I'll help you. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
greetings, I just discovered this library and so far like it a lot !
I'm using it mainly to feed my test db with fake data and I wondered if the approach I'm taking looks sensible or if there were more interesting ways to do that.
Currently I'm
schema.to_csv(file_path='data.csv', iterations=1000)
await conn.copy_to_table("products", source="data.csv", format="csv", header=True)
I was wondering if there was a more automated way to do this, this is currently very fast, the only small issue I have is that it is repetitive with table increases and hard to maintain with schema changes.
Beta Was this translation helpful? Give feedback.
All reactions