Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/spokanetech/exploring_orms
Exploring Go GORM and Django ORM
https://github.com/spokanetech/exploring_orms
Last synced: 9 days ago
JSON representation
Exploring Go GORM and Django ORM
- Host: GitHub
- URL: https://github.com/spokanetech/exploring_orms
- Owner: SpokaneTech
- Created: 2024-07-15T23:21:19.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-10-04T04:49:03.000Z (3 months ago)
- Last Synced: 2024-11-08T01:45:02.919Z (2 months ago)
- Language: HTML
- Homepage: https://spokanetech.github.io/exploring_orms/
- Size: 200 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
---
marp: true
theme: gaia
style: |
.columns {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 1rem;
}
section.small {
font-size: 22px;
}
---## Exploring GORM: The Fantastic ORM for Go
and the Django ORM for all you Pythonistas
---
## Agenda
We'll cover three main ideas:
- What is an ORM and why should you be using one?
- How to use GORM
- How does GORM compare to other popular ORMs
- Django ORM---
## What is an ORM?
**Object–relational mapping** is a technique for converting between relational databases and object-oriented programming languages.
| Database | Code |
| --- | --- |
| Table | Class / Model |
| Column | Field / Attribute |
| Relationships | Field / Attribute |---
## Why use an ORM?
- Typed interaction with your database
- Speed up development time
- Prevent SQL-injection
- Auto migrations
- ➖ Higher level abstraction
- ➖ Can lead to poor performance (N+1, etc.)---
## Relationships
- has one / belongs to
- has many
- many to many
- polymorphism
- single-table inheritance---
## Demo — Cars
- has one
- vehicle and driver
- has many
- vehicle and model
- model and manufacturer
- many to many
- model and parts
- polymorphism: gas and electric vehicles
- single-table inheritance---
## Has many
- A `manufacturer` has many `vehicles`
![width:600px](./docs/mermaid-1-simple.png)
---
## Many to many
- A `part` can fit many `vehicles` and a `vehicle` can have many `parts`
- When using GORM AutoMigrate, GORM will create join tables automatically![width:600px](./docs/mermaid-2-parts.png)
---
## Has one
- A `vehicle` has one driver, a `person`
![width:600px](./docs/mermaid-3-drivers.png)
---
## SQL vs. GORM vs. Django ORM functions
| SQL | GORM | GORM Gen | Django |
| --- | --- | --- | --- |
| SELECT * | `db.Select()` | `q.Person.Select()` | `queryset.all()` |
| SELECT name | `db.Select("name")` | `q.Person.Select(q.Person.Name)` | `queryset.values("name")` |
| WHERE name = 'Joe' | `db.Where("name=?","Joe")` | `q.Person.Where( q.Person.Name.Eq("Joe"))` | `queryset.filter(name="Joe")` |
| LIMIT | `.Limit(10)` | `q.Person.Limit(10)` | `qs[:10]` |---
## Repository pattern
---
## Active record vs. Data mapper
---
## Resources