Skip to main content

Posts

Showing posts with the label SQLAlchemy

Relational Database in Python-CRUD operations

Another post starts with you beautiful people! Hope you have enjoyed and learn from my previous post about  Relational Database In Python-sqlite Previously, we used the Table object to reflect a table from an existing database , but what if you wanted to create a new table? We'd still use the Table object; however, we'd need to replace the autoload and autoload_with parameters with Column objects . The Column object takes a name, a SQLAlchemy type with an optional format, and optional keyword arguments for different constraints. After defining the table, we can create the table in the database by using the .create_all() method on metadata and supplying the engine as the only parameter. You can find more details about metadata here-  tell me more about metadata! Output:- Well done! When creating a table, it's important to carefully think about what data types each column should be. Constraints and Data Defaults- We're now going to practice creating a t...

Relational Database in Python-SQLite

Another post starts with you beautiful people! Hope you have enjoyed and learnt my previous post about  file importing Today we will learn how as a Data Scientist we connect to the database step by step- Before starting the code first you must read about the very powerful library - SQLAlchemy which we will use in our exercises and you can find the details here-  SQLAlchemy documentation How To Create a Database Engine- Here, we're going to fire up our very first SQL engine. We'll create an engine to connect to the SQLite database 'Chinook.db'. You can find the download and installation steps of this sample database from here-  download sqlite sample database An engine is just a common interface to a database , and the information it requires to connect to one is contained in a connection string , such as sqlite:///C:\sqlite\db\chinook.db .Here, sqlite is the database driver , while chinook.db is a SQLite db file contained in the local directory. A little...