aurabase-js
v0.7.2
Published
AuraBase client library - Supabase-style SDK for AuraBase
Downloads
84
Maintainers
Readme
aurabase-js
AuraBase JavaScript/TypeScript 클라이언트 - Supabase 스타일의 SDK
설치
npm install aurabase-js
# 또는
yarn add aurabase-js
# 또는
pnpm add aurabase-js사용법
클라이언트 생성
import { createClient } from 'aurabase-js'
const aurabase = createClient({
url: 'http://localhost:8000', // 또는 배포된 URL
anonKey: 'your-anon-key'
})데이터 조회 (SELECT)
// 전체 조회
const { data, error } = await aurabase
.from('todos')
.select('*')
// 특정 컬럼 선택
const { data, error } = await aurabase
.from('todos')
.select('id, title, completed')
// 필터링
const { data, error } = await aurabase
.from('todos')
.select('*')
.eq('completed', false)
.order('created_at', { ascending: false })
.limit(10)
// 단일 결과
const { data, error } = await aurabase
.from('todos')
.select('*')
.eq('id', 1)
.single()데이터 삽입 (INSERT)
// 단일 행 삽입
const { data, error } = await aurabase
.from('todos')
.insert({ title: '새 할일', completed: false })
// 여러 행 삽입
const { data, error } = await aurabase
.from('todos')
.insert([
{ title: '할일 1', completed: false },
{ title: '할일 2', completed: true }
])데이터 수정 (UPDATE)
const { data, error } = await aurabase
.from('todos')
.update({ completed: true })
.eq('id', 1)데이터 삭제 (DELETE)
const { data, error } = await aurabase
.from('todos')
.delete()
.eq('id', 1)Upsert
const { data, error } = await aurabase
.from('todos')
.upsert({ id: 1, title: '업데이트된 할일', completed: true })인증 (Auth)
로그인
const { data, error } = await aurabase.auth.signInWithPassword({
email: '[email protected]',
password: 'password123'
})
if (data) {
console.log('로그인 성공:', data.user)
console.log('액세스 토큰:', data.session.access_token)
}회원가입
const { data, error } = await aurabase.auth.signUp({
email: '[email protected]',
password: 'password123',
username: 'myusername'
})로그아웃
await aurabase.auth.signOut()현재 사용자 조회
const { data: { user } } = await aurabase.auth.getUser()인증 상태 변경 감지
const { data: { subscription } } = aurabase.auth.onAuthStateChange((event, session) => {
if (event === 'SIGNED_IN') {
console.log('로그인됨:', session?.user)
} else if (event === 'SIGNED_OUT') {
console.log('로그아웃됨')
}
})
// 구독 해제
subscription.unsubscribe()비밀번호 재설정
await aurabase.auth.resetPasswordForEmail('[email protected]')필터 메서드
| 메서드 | 설명 | 예시 |
|--------|------|------|
| .eq(column, value) | 같음 | .eq('status', 'active') |
| .neq(column, value) | 같지 않음 | .neq('status', 'deleted') |
| .gt(column, value) | 초과 | .gt('age', 18) |
| .gte(column, value) | 이상 | .gte('age', 18) |
| .lt(column, value) | 미만 | .lt('price', 100) |
| .lte(column, value) | 이하 | .lte('price', 100) |
| .like(column, pattern) | LIKE 패턴 | .like('name', '%John%') |
| .ilike(column, pattern) | 대소문자 구분 없는 LIKE | .ilike('email', '%@gmail.com') |
| .in(column, values) | 값 목록 중 하나 | .in('id', [1, 2, 3]) |
| .isNull(column) | NULL | .isNull('deleted_at') |
| .isNotNull(column) | NOT NULL | .isNotNull('email') |
RPC (원격 함수 호출)
const { data, error } = await aurabase.rpc('my_function', {
arg1: 'value1',
arg2: 'value2'
})TypeScript 지원
interface Todo {
id: number
title: string
completed: boolean
created_at: string
}
// 타입 지정
const { data, error } = await aurabase
.from<Todo>('todos')
.select('*')
// data는 Todo[] 타입으로 추론됨라이선스
MIT
