https://github.com/waylonwalker/learn-sql-model
https://github.com/waylonwalker/learn-sql-model
Last synced: 12 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/waylonwalker/learn-sql-model
- Owner: WaylonWalker
- License: mit
- Created: 2023-05-19T13:34:45.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-07-02T14:32:39.000Z (about 3 years ago)
- Last Synced: 2025-02-22T12:45:26.587Z (over 1 year ago)
- Language: Python
- Size: 401 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Learn SQL Model
learning sql model
## Development
```console
pip install hatch
hatch shell
```
## Development with Docker
```console
docker compose build
docker compose up -d
```
To attach to the cli.
```console
docker attach learn-sql-model-cli-1
```
## Start the Server
```console
learn-sql-model api run
```
## Use the cli to manage Heros
```console
learn-sql-model hero create
# show them
learn-sql-model hero get
# show one
learn-sql-model hero get --id 0
```
## Use python to manage Heros
```python
from learn_sql_model.models.hero import Hero
# create a hero
bruce = Hero(name="Batman", secret_name="Bruce Wayne")
bruce.post()
# list all heros
Hero.get()
# get one hero
Hero.get(0)
```
## Use api to create hero
```console
# create a curl POST request to create hero
curl -X POST \
-H "Content-Type: application/json" \
-d '{"name": "Batman", "secret_name": "Bruce Wayne"}' \
http://localhost:5000/heros
# list all heros
curl http://localhost:5000/heros
curl -X 'GET' \
'http://localhost:5000/heros/' \
-H 'accept: application/json'
# get one hero
curl -X 'GET' \
'http://localhost:5000/hero/9' \
-H 'accept: application/json'
```
## Settings Management
config support `.env`, `.env.dev`, `.env.qa`, `.env.prod`.
```.env
ENV=dev
DATABASE_URL=sqlite:///db.sqlite
API_SERVER__PORT=8000
API_SERVER__RELOAD=False
API_SERVER__LOG_LEVEL=debug
```
## Populating the database
```bash
learn-sql-model hero populate
```
## Creating new modesl
```bash
learn-sql-model model create
```
## License
`learn-sql-model` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.