r/PythonLearning • • 1h ago

Showcase Database prototype (python)

I write my first data base code handling a class record using list tell me how is it..

First two are code and the rest is the output.

Tell me if anything can be improve or added to make this code even more practical.

9 Upvotes

7 comments sorted by

1

u/sleepbot63 1h ago

What's the goal may I ask ? coz I don't see a database here actually

1

u/Ender_Locke 42m ago

this is data, in lists not in a database

1

u/_GreyPrinceZot3_ 39m ago

cool, but this is just data as it is. make a function that saves data in a file (use jason, yaml or even ur custom parsing if you wanna do it for fun, its not that hard) everytime soemthing gets chenged, or when you want. if you want, i can send you a lil useless project that i made a few months ago

1

u/PureWasian 39m ago

Persistence. Your database is wiped as soon as you exit the runtime. A natural next progression would be writing the input/output data into a text/csv/json file per "session" running the script.

Then you'll realize, it only saves all of the updates if things exit gracefully. You should update per db write transaction.

Then you'll realize, only one person can edit the db at a time. You should add a locking mechanism so you don't have concurrent writes.

At this point, you'll discover that it's probably a good time to look into sqlite for a more "proper" local, lightweight db layer. Use that to learn how to write queries (and note that you would need to update a lot of your calling code accordingly).

If you wanted to go further, branch out from sqlite to PostgreSQL or some other more beefy and feature-rich db layer, or look into how cloud hosting solutions work to see how people typically save, access, and modify persistent data across multiple users.

1

u/Sidjeno 36m ago

use enums and named variable instead of magic variables.

Use an actual storage system, be it sqlite or json.

Tackle all the edge cases and make the system robust.

Develop a test suite to check for those edge cases.

1

u/zztopsboatswain 10m ago

This is a good prototype. Now look into SQLite or json to store the data, so you can save your changes