Closed patarapolw closed 4 years ago
I have found an answer, by using SQLAlchemy, minimally.
import dataset
import sqlalchemy as sa
db = dataset.connect('sqlite:///' + db_file)
if not os.path.exists(db_file):
sa.Table(
'patient', db.metadata,
sa.Column('patient_id', sa.Integer, primary_key=True)
).create()
sa.Table(
'patho_report', db.metadata,
sa.Column('id', sa.Integer, primary_key=True, autoincrement=True),
sa.Column('patho_id', sa.String, nullable=False, unique=True),
sa.Column('patient_id', sa.Integer, sa.ForeignKey('patient.patient_id')),
sa.Column('received', sa.DateTime)
).create()
You can now do:
import dataset
db = dataset.connect('sqlite:///' + db_file)
report = db['patho_report']
report.create_column('patho_id', nullable=False, unique=True)
Foreign keys are, I think, going to remain out of scope unless anyone comes up with a super Pythonic way to express them.
I would like to see these two, at least, in a schema-less NoSQL. How do I specify it is
dataset
?I managed to create such in TinyDB, but the main problems of TinyDB are:
insert_one
BTW, does
dataset
support blob?Another interesting thing is ForeignKey, but I believe it will never be supported, anyway.