전체 글
-
OPEN API 데이터 불러오기 ( fetch )React 2023. 3. 19. 20:23
fetch() : url을 입력하면 해당 데이터를 받아오는 함수로서, 인간인지 로봇인지 검사하지 않는 페이지라면 해당 함수로 정보를 받아올 수 있다 ( 검사하는 페이지라면 Selenium 등의 프로그램을 거쳐야한다 ) fetch("URL") - 기본적으로 해당 함수를 실행하면 여러가지 데이터들이 넘어온다 ( 기본적으로 페이지와 인터넷 연결이 잘 됬는지 확인하는 코드 ) 그래서 해당 페이지의 데이터를 취급하고 싶다면, response에서 json or xml을 추출해야한다 - 예제로 영화진흥위원회의 일별 박스오피스 정보를 가지고 와보자 useEffect(() => { -> 페이지가 로딩 되자마자 api 데이터를 가지고 오려면 useEffect()를 이용할 수 있다 fetch( `http://www.kobi..
-
데이터 타입(자료형 검사)Python 2023. 3. 18. 23:56
int와 string이 뒤석여있는 배열을 for 문을 활용해서 int 값들만 합을 구하는 문제가 있었다. numbers = [ int와 string이 뒤 섞인 값들 ] sum_result = 0 for num in numbers: if isinstance(num,int): sum_result = sum_result + num print(sum_result) - 다음과 같이 for 문 내부에 if문으로 배열의 값이 int인지 아닌지 검사하는 명령어를 넣어서 해결했다. python에서 타입을 확인하는 방법 두가지가 있다 type 과 isinstance 이다. 둘의 차이점으로 type은 해당 데이터의 type을 반환하고 isinstance는 true/false로 반환한다 type(데이터) -> 데이터의 타입을..
-
My Sql 첫걸음 CH08. 트랜잭션Sql 2023. 3. 17. 15:05
1 _ 트랜잭션 : insert나 update 명령으로 데이터를 추가, 갱신할 때도 트랜잭션 기능을 사용하지만, 자동 커밋 기능이 동작했기 때문에 눈치 체지 못 했을 것이다. 트랜잭션의 제어 START TRANSACTION COMMIT ROLLBACK -> insert나 update 기능을 사용할 때 해당 기능들이 모두 성공하면 commit 기능들 중에 하나라도 실패했다면 rollback한다. - transaction 없이 update하면 count에 +1이 되며 자동으로 commit 된다 하지만 transaction을 시작한 후 update 나 insert 명령을 정상적으로 수행했다면, commit; 명령으로 commit 시켜줘야한다. 만일 update 나 insert 명령이 정상적이지 않았다면, tr..
-
My Sql 첫걸음 CH08. 데이터베이스 설계Sql 2023. 3. 17. 15:02
1 _ 데이터베이스 설계 : 데이터베이스의 스키마 내에 테이블, 인덱스, 뷰 등의 데이터베이스 객체를 정의하는 것을 말한다. 스키마 내에 정의한다는 뜻에서 '스키마 설계'라 불리기도 한다. 데이터 베이스에서 사용될 이름으로 논리명과 물리명이 있다. 논리명 : 테이블의 설계상 이름 물리명 : create table 처럼 지정하는 이름을 말한다. 2 _ er 다이어그램 : 테이블 간의 관계를 명확히 하기 위해서 설계도를 작성한다. erd 관계선 종류 실선 : 부모 테이블 pk 가 자식 테이블 fk가 되는 경우 점선 : 부모 테이블 pk 가 자식 테이블의 일반속성이 되는 경우 erd 기호의 종류 | : 1개 < : 여러개 o : 0개 선 끝에 3지창으로 되어있는 곳은 선이 나오는 지점에서 3지창 방향의 테이블..
-
nomad) react .map( )React 2023. 3. 17. 14:05
.map( ) : 이 메소드를 이용하면 배열에 들어있는 모든 요소들에 실행문을 할 수 있다 ( foreach 랑 비슷하다 ) toDos = [ 1, 2, werq, 523 ] 같은 배열이 있다고 보자 toDos.map( ) -> .map 메소드의 첫 번째 인수는 배열 내부의 값들이다. 배열 내부의 값들을 하나씩 가지고나온다 두 번째 인수는 배열 값의 index이다. 따라서 우리는 값과 순서를 알 수 있다. toDos.map( (item,index) => ( {item} ) ) -> li 를 생성한다 , 각 li는 toDos 배열의 값과 index를 내용과 키 값으로 받는다 ** 해당 함수에서 item 과 index의 이름은 사용자가 자유롭게 지정할 수 있다 ** react의 특성상 같은 component..
-
nomad) react useState( [] ) 활용React 2023. 3. 17. 11:59
todo 리스트를 만들 때 const [ toDo, setToDo ] = useState( "" ); const [ toDos, setToDos ] = useState( [] ); 로 선언할 경우 배열로 초기값이 지정된 toDos 에 값을 추가하고 싶다면, setToDos(currentArray => [ toDo, ...currentArray ]); 를 사용한다. -> ...currentArray는 현재 currentArray 내부에 있는 값들을 모두 출력하는 명령어로, 위의 상태에서는 toDos 배열에 저장된 모든 값들을 출력한다고 할 수 있다. 따라서 기존에 있던 toDos 배열에 toDo 값을 지정해서 다시 toDos 배열에 저장하고자 한다. - input에 넣고 submit 한 string이 to..
-
Foreign key ( 외래키 )Sql 2023. 3. 17. 11:41
외래키 ( Foreign key ) : 여러개의 테이블이 있을 때 데이터 무결성을 유지하기 위해 중요하다. 외래키를 설정하면 참조 무결성을 강제할 수 있으며, 다른 테이블의 데이터를 변경할 때 해당 외래키를 참조하는 모든 테이블의 데이터도 함께 변경된다. 이를 통해 데이터 일관성과 정확성을 유지할 수 있다. - 외래키로 설정하기 위해서는 기본적으로 primary key 설정이 되어있어야한다. - 외래키와 기본키의 타입이 일치해야한다. - 다음과 같이 예를 들 수 있다. 위 예시에서는 orders 테이블의 product_id 피륻가 products 테이블의 product_id 필드를 참조하도록 외래키 제약조건을 설정했다. orders 테이블의 product_id 필드는 products 테이블의 produc..