Develop/FastAPI
FastAPI SQLite3 Setting Up Todos - 36
김잠봉
2022. 12. 30. 23:48
728x90
터미널로 sqllite3 데이터베이스를 조작하는 것이 목표
파이썬 사용 툴: Pycharm / 운영체제: Mac
1. pycharm 터미널에서 데이터베이스 접속하기 해당 값을 입력
sqlite3 todos.db
2. 데이터베이스 내의 테이블을 확인
sqlite> .schema
3. 테이블에 데이터를 삽입해 보기
sqlite> insert into todos (title, description, priority, complete) values ('Go to the store', 'Pick up eggs', 5, False);
sqlite> insert into todos (title, description, priority, complete) values ('Cut the lawn', 'Grass is getting long', 3, False);
sqlite> insert into todos (title, description, priority, complete) values ('Feed the dog', 'He is getting hungry', 5, False);
4. 테이블의 데이터를 조회해 보기
sqlite> select * from todos;
5. 조회 결과 모드를 변경해 보기
#조회결과가 예쁘지 않다. 변경해보자
sqlite> .mode column
sqlite> select * from todos;
sqlite> .mode markdown
sqlite> select * from todos;
sqlite> .mode box
sqlite> select * from todos;
sqlite> .mode table
sqlite> select * from todos;
6. 추가적인 데이터 삽입 후 삭제해 보기
sqlite> insert into todos (title, description, priority, complete) values ('Test element', 'He is getting hungry', 5, False);
sqlite> select * from todos;
sqlite> delete from todos where id = 4;
sqlite> select * from todos;
7. 한번 더 삭제해 보기
sqlite> insert into todos (title, description, priority, complete) values ('A new test element', 'He is getting hungry', 5, False);
sqlite> select * from todos;
sqlite> delete from todos where id = 4;
sqlite> select * from todos;
※ 위 과정에서 id = 4를 지우고 다시 추가를 해도 id는 4로 다시 삽입이 되는 것을 볼 수 있다.
728x90
SMALL