내일배움캠프

230821 supabase query count

Neda 2023. 8. 21. 21:04

230821 supabase query count 

수파베이스에서 count qeury하기

Select에서 count 사용하기

유저 테이블의 유저가 총 몇명인지 찾기 위해 count를 사용

  const getAllUserCount = async () => {
    const { count, error } = await supabase
      .from("user")
      .select("*", { count: "exact", head: true });
    console.log(count, error);
  };

 

job 컬럼에서 값이 '개발자'인 행만 count하여 개발자 직업을 가진 유저가 몇 명인지 구하기

  const getStudentUserCount = async () => {
    const { count, error } = await supabase
      .from("user")
      .select("*", { count: "exact", head: true })
      .eq("job", "학생");
    console.log(count, error);
  };

 

age 컬럼의 값이 20 이상인 행만 count 하여 성인 유저가 몇 명인지 구하기

  const getAdultUserCount = async () => {
    const { count, error } = await supabase
      .from("user")
      .select("*", { count: "exact", head: true })
      .gte("age", 20);
    console.log(count, error);
  };

 

 


 

Fetch data | Supabase

Perform a SELECT query on the table or view.

supabase.com