✍ 따뜻한 개발 공부
임시 메모장 - 수파베이스 관련
따따시
2023. 1. 22. 23:12
>> 데이터 테이블 구조에유
* supabase는 진짜 sql이라서 고유한 id값 들어간 컬럼 생성햇어용
company | commute | convenient | restaurant | pros1 | pros2 | pros3 | pros4 | pros5 | cons1 | cons2 | cons3 | cons4 | cons5 |
kakao | 5 | 3 | 2 | 1 | 0 | 1 | 1 | 0 | 1 | 1 | 0 | 1 | 1 |
kakao | 3 | 5 | 4 | 0 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 1 | 1 |
naver | 4 | 1 | 3 | 1 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
kakao | 2 | 5 | 2 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 |
kakao | 5 | 3 | 2 | 1 | 0 | 1 | 1 | 0 | 1 | 1 | 0 | 1 | 1 |
kakao | 5 | 3 | 2 | 1 | 0 | 1 | 1 | 0 | 1 | 1 | 0 | 1 | 1 |
>> 테이블만 조회해오는 코드
import { useEffect } from "react";
import { useLocation } from "react-router-dom";
import { supabase } from "../util/supabase";
const CompanyPage = () => {
const location = useLocation();
const urlReqCompanyName = location.state["companyName"];
// supabase연결되었는지 찍어봤음
console.log("supabase:", supabase);
// supabase에서 table 가져오는 함수
const getTable = async () => {
const { data, error } = await supabase
.from("testTable")
.select()
.eq("company", "kakao");
const prosArray: number[] = [];
if (data) {
console.log(data);
data?.map((item: any) => {
console.log("item:", item.pros);
prosArray.push(item.pros);
console.log("난 prosArray얌", prosArray);
let result: number = prosArray.reduce(
(total: number, value: number) => (total += value),
0
);
console.log("result가 2가 나와야댕 : ", result);
});
}
if (error) {
console.log(error);
}
};
// useEffect 부분
useEffect(() => {
getTable();
}, []);
return (
<div>
<h3>urlRequest:{urlReqCompanyName}</h3>
{/* <h3>pros1의 합계 : {pros1State}</h3> */}
</div>
);
};
export default CompanyPage;
>> table에 인설트 시키는 코드
https://supabase.com/docs/reference/javascript/insert
https://supabase.com/docs/reference/javascript/insert
Perform an INSERT into the table or view.
supabase.com