30
loading...
This website collects cookies to deliver better user experience
// Insert a row
const { data, error } = await supabase
.from('notes')
.insert([
{ note: 'I need to not forget this' },
])
// Grab our credentials from a .env file or environment variables
require('dotenv').config();
const {
DATABASE_URL,
SUPABASE_SERVICE_API_KEY
} = process.env;
// Connect to our database
const { createClient } = require('@supabase/supabase-js');
const supabase = createClient(DATABASE_URL, SUPABASE_SERVICE_API_KEY);
// Our standard serverless handler function
exports.handler = async event => {
// Insert a row
const { data, error } = await supabase
.from('notes')
.insert([
{ note: 'I need to not forget this' },
]);
// Did it work?
console.log(data, error);
}
netlify/functions
folder in our project, and Netlify will deploy it for us and give us a URL which will invoke it.// Get everything from the notes table
let { data: notes, error } = await supabase
.from('notes')
.select('*')
// Just return the date and note columns of every note
let { data: notes, error } = await supabase
.from('notes')
.select('date, note')
eq()
to find a record which matches a value:let id = "some_id_we_are_curious_about";
let { data: notes, error } = await supabase
.from('notes')
.select('date, note')
.eq('id', id)
.eq('column', 'Equal to')
.gt('column', 'Greater than')
.lt('column', 'Less than')
.gte('column', 'Greater than or equal to')
.lte('column', 'Less than or equal to')
.like('column', '%CaseSensitive%')
.ilike('column', '%CaseInsensitive%')
.is('column', null)
.in('column', ['Array', 'Values'])
.neq('column', 'Not equal to')