Python
Simple working with SQL database with SQLModel
SQLModel is based on pydantic and SQLAlchemy. The library provides great support in code editors like Visual Studio Code and Pycharm. Let’s go with some simple queries, orms and create data into Postgresql database with SQLModel.
First we create a new user for Postgres database
create user testuser with encrypted password 'testuser';
Then we will create a new database in Postgres name testdb
CREATE DATABASE testdb OWNER testuser;
We will create a new virtual environment for Python, then install sqlmodel library
pip install sqlmodel
If you’re using Ubuntu like me, you would also need to install psycopg2-binary:
pip install psycopg2-binary
Ok, so let’s create an example for adding new data to our testdb