This repository has been archived by the owner on Jan 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add archived posts and modify README.md
- Loading branch information
Showing
11 changed files
with
660 additions
and
49 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,13 @@ | ||
# ๐ฉ๐ปโ๐ป TIL | ||
[](https://app.netlify.com/sites/todayejlearned/deploys) | ||
|
||
This repository is for the things I learned today. | ||
|
||
The website for this repo was generated by [docsify.js](https://docsify.js.org/#/) and deployed by [netlify](https://todayejlearned.netlify.com). | ||
|
||
## Getting started | ||
|
||
### Prerequisites | ||
|
||
First, clone this repo. | ||
``` | ||
git clone https://github.com/ejolie/TIL.git | ||
``` | ||
|
||
### Install | ||
|
||
It is recommended to install `docsify-cli` globally, which helps initializing and previewing the website locally. | ||
```bash | ||
npm i docsify-cli -g | ||
``` | ||
|
||
## Preview | ||
Change directory to `docs/` directory and run the local server with `docsify serve`. | ||
|
||
You can preview your site in your browser on `http://localhost:3000`. | ||
|
||
```bash | ||
cd docs | ||
docsify serve docs | ||
``` | ||
[](https://app.netlify.com/sites/todayejlearned/deploys) | ||
|
||
## Deployment | ||
I recommend you to read an official document of [docsify.js](https://docsify.js.org/#/deploy). | ||
์ค๋ ๋ฐฐ์ด ๋ด์ฉ์ ์ ๋ฆฌํ๋ ์ ์ฅ์์ ๋๋ค. | ||
|
||
You can deploy files to GitHub Pages, Netlify, etc. | ||
์ด ์ ์ฅ์๋ [docsify.js](https://docsify.js.org/#/)๋ฅผ ์ด์ฉํด ์น ์ฌ์ดํธ๋ก ๋ง๋ค์ด์ก์ผ๋ฉฐ [netlify](https://todayejlearned.netlify.com)๋ก ๋ฐฐํฌ๋์์ต๋๋ค. | ||
|
||
## Screenshot | ||
|
||
<img src="./assets/main.png" alt="TIL - main" width="800"> | ||
|
||
<img src="./assets/detail.png" alt="TIL - detail" width="800"> | ||
|
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# Today I Learned | ||
# Today I Learned | ||
|
||
>:pencil2: ์ค๋ ๋ฐฐ์ด ๋ด์ฉ์ ์ ๋ฆฌํฉ๋๋ค. | ||
> :pencil2: ๊ฐ์, ๋ธ๋ก๊ทธ, ๊ณต์ ๋ฌธ์ ๋ฑ์ ๋ณด๊ณ ๋ฐฐ์ด ๋ด์ฉ์ ์ ๋ฆฌํฉ๋๋ค. |
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,78 @@ | ||
2019๋ 2์ 14์ผ ๋ชฉ์์ผ | ||
|
||
# Django ๊ฐ์ํ๊ฒฝ ์ค์ ๊ณผ ์ฃผ์ ๋ช ๋ น์ด | ||
|
||
## pyenv, virtualenv ์ค์น | ||
|
||
```bash | ||
> git clone https://github.com/pyenv/pyenv.git ~/.pyenv | ||
> echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc | ||
> echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc | ||
> echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.bashrc | ||
> exec "$SHELL" | ||
> git clone https://github.com/pyenv/pyenv-virtualenv.git $(pyenv root)/plugins/pyenv-virtualenv | ||
> echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc | ||
> exec "$SHELL" | ||
``` | ||
|
||
## ๊ฐ์ํ๊ฒฝ ์์ฑ ๋ฐ ์ค์ | ||
|
||
```bash | ||
> mkdir TEST | ||
> cd TEST | ||
> pyenv virtualenv 3.6.7 <VENV_NAME> | ||
> pyenv local <VENV_NAME> | ||
> pip install django | ||
``` | ||
|
||
## Project ์์ฑ | ||
|
||
```bash | ||
> django-admin startproject <PROJECT_NAME> . | ||
``` | ||
|
||
## App ์์ฑ | ||
|
||
```bash | ||
> python manage.py startapp <APP_NAME> | ||
``` | ||
|
||
## Server ์คํ | ||
|
||
```bash | ||
> python manage.py runserver $IP:$PORT | ||
``` | ||
|
||
## Migrations | ||
|
||
```bash | ||
> python manage.py makemigrations # Table ์์ฑ | ||
> python manage.py sqlmigrate articles 0001 # SQL๋ก ์ด๋ป๊ฒ ๋ง๋๋์ง ๋ณด์ฌ์ค | ||
> python manage.py migrate # DB์ ์ ์ฉ | ||
``` | ||
|
||
## Shell ์คํ | ||
|
||
```bash | ||
> python manage.py shell | ||
``` | ||
|
||
```shell | ||
# python console | ||
> from articles.models import Article | ||
> a = Article(title="์ ์ฌ๊ธฐ์๋ ๊ธ์ด ์จ์ง๋ค!!", content="์ฅ๊ณ ์งฑ์งฑ๋งจ") | ||
> a.save() | ||
> Article.objects.all() | ||
<QuerySet [<Article: Article object (1)>, <Article: Article object (2)>]> | ||
> Article.objects.first() | ||
<Article: ์ ๋ชฉ: happy, ๋ด์ฉ: hacking> | ||
``` | ||
|
||
> - Flask : Article.query.all() | ||
> - Django : Article.objects.all() | ||
## Admin ์ค์ | ||
|
||
```bash | ||
> python manage.py createsuperuser | ||
``` |
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,26 @@ | ||
2019๋ 2์ 20์ผ ์์์ผ | ||
|
||
# Django ํ์ค CRUD์ RESTful API | ||
|
||
## RESTful API | ||
|
||
- **REST** : **Re**presentational **S**tate **T**ransfer | ||
|
||
## 1. Read | ||
|
||
- `articles/` : ๋ฆฌ์คํธ ํ์ด์ง | ||
- `articles/1` : ๋ํ ์ผ ํ์ด์ง | ||
|
||
## 2. Create | ||
|
||
- `articles/new` : ๊ธ ์์ฑ ํ์ด์ง | ||
- `articles/create` : ๊ธ ์์ฑ DB ๋ฐ์ | ||
|
||
## 3. Update | ||
|
||
- `articles/1/edit` : ๊ธ ์์ ํ์ด์ง | ||
- `articles/1/update` : ๊ธ ์์ DB ๋ฐ์ | ||
|
||
## 4. Delete | ||
|
||
- `articles/1/delete` : ๊ธ ์ญ์ ํ์ด์ง |
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,168 @@ | ||
2019๋ 2์ 21์ผ ๋ชฉ์์ผ | ||
|
||
# Django ORM | ||
|
||
## `__repr__` ๊ณผ `__str__`์ ์ฐ๋ ์ด์ | ||
|
||
## `def __repr__(self)` | ||
|
||
```python | ||
# models.py | ||
def __repr__(self): | ||
return f'์ ๋ชฉ: {self.title}, ๋ด์ฉ: {self.content}' | ||
``` | ||
|
||
```bash | ||
# python console | ||
> Article.objects.all() | ||
<QuerySet [์ ๋ชฉ: happy, ๋ด์ฉ: hacking, ์ ๋ชฉ: ์ ์ฌ๊ธฐ์๋ ๊ธ์ด ์จ์ง๋ค!!, ๋ด์ฉ: ์ฅ๊ณ ์งฑ์งฑ๋งจ] | ||
> Article.objects.first() | ||
์ ๋ชฉ: happy, ๋ด์ฉ: hacking | ||
``` | ||
|
||
```bash | ||
> for a in Article.objects.all(): | ||
> print(a) | ||
Article object (1) | ||
Article object (2) | ||
``` | ||
```bash | ||
> for a in Article.objects.all() | ||
> a | ||
์ ๋ชฉ: happy, ๋ด์ฉ: hacking | ||
์ ๋ชฉ: ์ ์ฌ๊ธฐ์๋ ๊ธ์ด ์จ์ง๋ค!!, ๋ด์ฉ: ์ฅ๊ณ ์งฑ์งฑ๋งจ | ||
``` | ||
## `def __str__(self)` | ||
```python | ||
# models.py | ||
def __str__(self): | ||
return f'์ ๋ชฉ: {self.title}, ๋ด์ฉ: {self.content}' | ||
``` | ||
```bash | ||
# python console | ||
> for a in Article.objects.all(): | ||
> print(a) | ||
์ ๋ชฉ: happy, ๋ด์ฉ: hacking | ||
์ ๋ชฉ: ์ ์ฌ๊ธฐ์๋ ๊ธ์ด ์จ์ง๋ค!!, ๋ด์ฉ: ์ฅ๊ณ ์งฑ์งฑ๋งจ | ||
``` | ||
# ORM Query ์กฐ์ | ||
## 1. Create | ||
```bash | ||
# python console | ||
# method 1 | ||
> a = Article(title="happy", content="hacking") | ||
> a.save() | ||
``` | ||
```bash | ||
# method 2 | ||
> Article.objects.create(title="hey!", content="create") | ||
``` | ||
## 2. Read | ||
### Select | ||
```bash | ||
# python console | ||
> Article.objects.filter(title="happy").all() | ||
> Article.objects.filter(title="happy").first() | ||
``` | ||
> - Flask : Article.query.filter_by(title="happy").all() | ||
> | ||
> - Django : Article.objects.filter(title="happy").all() | ||
### Select By | ||
```bash | ||
# python console | ||
> Article.objects.get(pk=1) # primary key | ||
> Article.objects.get(id=1) # column : id | ||
> Article.objects.get(title="happy") # column : title | ||
> Article.objects.filter(title="happy").first() # get(title="happy")์ ๋์ผ | ||
``` | ||
### Count | ||
```bash | ||
# python console | ||
> Article.objects.filter(content="hacking").count() | ||
> len(Article.objects.all()) | ||
2 | ||
> Article.objects.all().count() | ||
2 | ||
``` | ||
### order_by | ||
```python | ||
# python console | ||
> Article.objects.order_by('id').all() # ์ค๋ฆ์ฐจ์ | ||
> Article.objects.order_by('-id').all() # ๋ด๋ฆผ์ฐจ์ | ||
``` | ||
## 3. Update | ||
```bash | ||
# python console | ||
> a = Article.objects.get(id=1) | ||
> a.content = "Thursday" | ||
> a.save() | ||
> Article.objects.get(id=1) | ||
์ ๋ชฉ: happy, ๋ด์ฉ: Thursday | ||
``` | ||
## 4. Delete | ||
```bash | ||
# python console | ||
> a = Article.objects.get(id=2) | ||
> a.delete() | ||
``` | ||
# Django CRUD | ||
## ํจํค์ง ์ค์น | ||
```bash | ||
> pip install django ipython django_extensions | ||
``` | ||
## DB ์คํ | ||
```bash | ||
> sqlite3 db.sqlite3 # sqlite3์ผ๋ก ์คํ | ||
> python manage.py dbshell # DB shell ์๋ ์คํ(sqlite3) | ||
``` | ||
``` | ||
> python manage.py shell | ||
``` | ||
`ipython`, `django_extensions` ํจํค์ง ๋๋ถ์ ์ฃผํผํฐ ๋ ธํธ๋ถ๊ณผ ๊ฐ์ ํ๊ฒฝ์์ ํ์ด์ฌ ์ฝ์์ ์ฌ์ฉํ ์ ์๋ค. | ||
```bash | ||
> python manage.py shell_plus | ||
``` | ||
์ฅ๊ณ ์ ๋ค์ด๊ฐ ๋ชจ๋ ํ๊ฒฝ์ autoload ํด์ค๋ค. `from articles.models import Article` ๊ณผ ๊ฐ์ ์์ ์ ํ์ง ์์๋ ๋๋ค. | ||
# Django ORM Relationships | ||
```bash | ||
> Comment.objects.filter(article_id=1).all | ||
> Article.objects.first().comment_set.all() | ||
``` | ||
```bash | ||
> Comment.objects.first().article | ||
> Article.objects.all().get(pk=Comment.objects.first().article_id) | ||
``` |
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,28 @@ | ||
2019๋ 5์ 1์ผ ์์์ผ | ||
|
||
# React Apollo | ||
|
||
## GraphQL? | ||
|
||
GraphQL์ ์๋ฒ API๋ฅผ ํตํด ์ ๋ณด๋ฅผ ์ฃผ๊ณ ๋ฐ๊ธฐ ์ํด ์ฌ์ฉํ๋ ์ฟผ๋ฆฌ์ด๋ค. GraphQL API๋ ๋ณดํต ํ๋์ ์๋ํฌ์ธํธ๋ฅผ ์ฌ์ฉํ๋ฉฐ, ์์ฒญ์ ์ฌ์ฉํ๋ ์ฟผ๋ฆฌ๋ฌธ์ ๋ฐ๋ผ ์๋ต์ ๊ตฌ์กฐ๊ฐ ๋ฌ๋ผ์ง๋ค. | ||
|
||
## Apollo Client? | ||
|
||
Apollo Client๋ ํด๋ผ์ด์ธํธ ์ ํ๋ฆฌ์ผ์ด์ ์์ GraphQL๊ณผ์ ๋ฐ์ดํฐ ๊ตํ์ ๋์ฐ๋ฉฐ, ํน๋ณํ ๋ฆฌ์กํธ์์ ์ฌ์ฉํ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ React Apollo๋ผ๊ณ ๋ถ๋ฅธ๋ค. | ||
|
||
์์ฑ๋ GraphQL ์ฟผ๋ฆฌ๋ Apollo Client์์ ์ปดํฌ๋ํธ์ ํจ๊ป ์ฌ์ฉํ ์ ์๋ค. | ||
|
||
* Query - Retrieve Data ("GET") | ||
* Mutation - Manipulate Data ("POST", "PUT", "PATCH", "DELETE") | ||
* SUbscription - Set up realtime connection via Websockets | ||
|
||
### Query | ||
|
||
๋ฐ์ดํฐ๋ฅผ ๋ฐ์์ฌ ๋ Query ์ปดํฌ๋ํธ๋ฅผ ์ฌ์ฉํ๋ค. ์ด ์ปดํฌ๋ํธ๋ฅผ ์ฌ์ฉํ๊ธฐ ์ํด์๋ GraphQL ์ฟผ๋ฆฌ๋ฅผ props๋ก ๋ฃ์ด์ค์ผ ํ๋ค. | ||
|
||
Query ์ปดํฌ๋ํธ์ ํ๋ผ๋ฏธํฐ๋ก loading, error์ ํจ๊ป Query ์ปดํฌ๋ํธ๊ฐ ์ ๊ณตํ๋ data๋ฅผ ๋๊ฒจ์ค๋ค. Query ์ปดํฌ๋ํธ๊ฐ ๋ง์ดํธ๋๋ฉด, ์ํด๋ก ํด๋ผ์ด์ธํธ๋ ์ฟผ๋ฆฌ์๋ํ observer๋ฅผ ์์ฑํ๋ค. ์ปดํฌ๋ํธ๋ ์ํด๋ก ํด๋ผ์ด์ธํธ ์บ์๋ฅผ ํตํด ์ฟผ๋ฆฌ์ ๋ํ ๊ฒฐ๊ณผ๊ฐ์ ๊ตฌ๋ ํ๋ค. ๋จผ์ , ์ฟผ๋ฆฌ ๊ฒฐ๊ณผ๊ฐ์ ์ํด๋ก ์บ์๋ก๋ถํฐ ๊ฐ์ ธ์จ๋ค. ์์ ๊ฒฝ์ฐ, ์๋ฒ๋ก ์์ฒญ์ ๋ณด๋ด๋ฉฐ, ๋ฐ์ดํฐ๋ฅผ ๋ฐ์ผ๋ฉด ์ํด๋ก ์บ์์ ์ ์ฅ์ ํ๋ค. | ||
|
||
|
||
|
||
|
||
์ถ์ฒ : https://medium.com/@shlee1353/%EB%A6%AC%EC%95%A1%ED%8A%B8-%EC%95%84%ED%8F%B4%EB%A1%9C-react-apollo-%EB%A6%AC%EB%8D%95%EC%8A%A4%EC%99%80-%EB%AC%B4%EC%97%87%EC%9D%B4-%EB%8B%A4%EB%A5%B8%EA%B0%80-a4bfdb48bbc |
Oops, something went wrong.