mirror of
https://github.com/supabase/supabase.git
synced 2026-07-06 03:54:27 +08:00
97 lines
2.4 KiB
JavaScript
97 lines
2.4 KiB
JavaScript
export default [
|
|
{
|
|
lang: 'js',
|
|
title: 'Create user',
|
|
description: 'Sign up a new user in an example chat room',
|
|
code: `import { createClient } from '@supabase/supabase-js'
|
|
|
|
// Initialize
|
|
const supabaseUrl = 'https://chat-room.supabase.co'
|
|
const supabaseKey = 'public-anon-key'
|
|
const supabase = createClient(supabaseUrl, supabaseKey)
|
|
|
|
// Create a new user
|
|
const { user, error } = await supabase.auth.signUpWithPassword({
|
|
email: '[email protected]',
|
|
password: 'example-password',
|
|
})
|
|
`,
|
|
},
|
|
{
|
|
lang: 'js',
|
|
title: 'Realtime subscriptions',
|
|
description: 'Receive realtime messages in an example chat room',
|
|
code: `import { createClient } from '@supabase/supabase-js'
|
|
|
|
// Initialize
|
|
const supabaseUrl = 'https://chat-room.supabase.co'
|
|
const supabaseKey = 'public-anon-key'
|
|
const supabase = createClient(supabaseUrl, supabaseKey)
|
|
|
|
// Get notified of all new chat messages
|
|
const realtime = supabase
|
|
.from('messages')
|
|
.on('INSERT', message => {
|
|
console.log('New message!', message)
|
|
})
|
|
.subscribe()
|
|
`,
|
|
},
|
|
{
|
|
lang: 'js',
|
|
title: 'Read a record',
|
|
description: 'Get all public rooms and their messages',
|
|
code: `import '@supabase/supabase-js'
|
|
|
|
// Initialize
|
|
const supabaseUrl = 'https://chat-room.supabase.co'
|
|
const supabaseKey = 'public-anon-key'
|
|
const supabase = createClient(supabaseUrl, supabaseKey)
|
|
|
|
// Get public rooms and their messages
|
|
const publicRooms = await supabase
|
|
.from('rooms')
|
|
.select(\`
|
|
name,
|
|
messages ( text )
|
|
\`)
|
|
.eq('public', true)
|
|
`,
|
|
},
|
|
{
|
|
lang: 'js',
|
|
title: 'Create a record',
|
|
description: 'Create a new chat room',
|
|
code: `import { createClient } from '@supabase/supabase-js'
|
|
|
|
// Initialize
|
|
const supabaseUrl = 'https://chat-room.supabase.co'
|
|
const supabaseKey = 'public-anon-key'
|
|
const supabase = createClient(supabaseUrl, supabaseKey)
|
|
|
|
// Create a new chat room
|
|
const newRoom = await supabase
|
|
.from('rooms')
|
|
.insert({ name: 'Supabase Fan Club', public: true })
|
|
`,
|
|
},
|
|
{
|
|
lang: 'js',
|
|
title: 'Update a record',
|
|
description: 'Update a user',
|
|
code: `import { createClient } from '@supabase/supabase-js'
|
|
|
|
// Initialize
|
|
const supabaseUrl = 'https://chat-room.supabase.co'
|
|
const supabaseKey = 'public-anon-key'
|
|
const supabase = createClient(supabaseUrl, supabaseKey)
|
|
|
|
// Update multiple users
|
|
const updatedUsers = await supabase
|
|
.from('users')
|
|
.eq('account_type', 'paid')
|
|
.update({ highlight_color: 'gold' })
|
|
`,
|
|
},
|
|
]
|