-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Hyeon <[email protected]> Co-authored-by: heumsi <[email protected]>
- Loading branch information
1 parent
3462b0e
commit 0b70dd5
Showing
13 changed files
with
3,279 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
home: true | ||
heroImage: https://media.vlpt.us/images/zamonia500/post/6dd8b08b-a089-49db-a2f1-921ad6a9649e/connect-a-flask-app-to-a-mysql-database-with-sqlalchemy-and-pymysql.jpg | ||
tagline: This is a document that simplifies SQLAlchemy for easy understanding. | ||
actionText: Tutorial → | ||
actionLink: /en/tutorial/ | ||
footer: Made by soogoonsoogoon pythonists ❤️ | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Tutorial Overview | ||
|
||
<br> | ||
|
||
## Overview | ||
|
||
SQLAlchemy is a library in Python that facilitates the connection to databases and the use of ORM (Object-Relational Mapping). | ||
For instance, you can execute specific queries in your code and perform a series of operations in the database through ORM objects. | ||
|
||
<br> | ||
|
||
## Installation | ||
|
||
SQLAlchemy can be installed as follows: | ||
|
||
```bash | ||
$ pip install sqlalchemy | ||
``` | ||
|
||
The version being used is as follows: | ||
|
||
```python | ||
>>> import sqlalchemy | ||
>>> sqlalchemy.__version__ | ||
1.4.20 | ||
``` | ||
|
||
<br> | ||
|
||
## Offerings | ||
|
||
SQLAlchemy is offered in the following two ways: | ||
|
||
- **Core** | ||
- This is the database toolkit and the foundational architecture of SQLAlchemy. | ||
- It manages connections to databases, interacts with database queries and results, and provides tools to programmatically compose SQL statements. | ||
- **ORM** | ||
- Built on top of Core, it provides optional **ORM** (Object-Relational Mapping) features. | ||
|
||
It is generally recommended to understand Core first before using ORM. | ||
This tutorial will start by explaining Core. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Setting up a Connection | ||
|
||
<br> | ||
|
||
## Connecting to a Database | ||
|
||
Let's try connecting to SQLite, a relatively lightweight database. | ||
You can do it as follows: | ||
|
||
```python | ||
>>> from sqlalchemy import create_engine | ||
>>> engine = create_engine("sqlite+pysqlite:///:memory:", echo=True, future=True) | ||
``` | ||
|
||
- Use the `sqlalchemy.create_engine` function to create an **'engine'** that establishes a connection to the database. | ||
- The first argument is a **`string URL`**. | ||
- Typically, the `string URL` is structured as `dialect+driver://username:password@host:port/database`. | ||
- If you don't specify a `driver`, SQLAlchemy's default settings will be used. | ||
- Here, `sqlite+pysqlite:///test.db` is the `string URL`. | ||
- For `sqlite`, the format follows `sqlite://<nohostname>/<path>`. | ||
- From the string URL `sqlite:///test.db`, we can understand the following information: | ||
- **Which database** to use (`dialect`, in this case, `sqlite`) | ||
- **Which database API** (the driver interacting with the database) to use (in this case, `pysqlite`) | ||
- **How to find** the database (in this case, it uses the in-memory feature provided by `sqlite`) | ||
- Setting the `echo` parameter to `True` prints all executed SQL. | ||
|
||
Creating an engine doesn't yet attempt an actual connection. The real connection occurs only when a request to perform an operation on the database is received for the first time. |
Oops, something went wrong.