whaley
09/25/2022, 2:20 PMpvtctrlalt
09/25/2022, 2:45 PMexport async function sendDeviceDetails() {
const devd = await store.getDeviceInfo();
console.log(devd);
const { data, error } = await supabase
.from('devicedetails')
.upsert([
{ UUID: devd.system.uuid },
{ systeminfo: JSON.stringify(devd) },
])
if (error){ console.log(error); return error;}
console.log(data);
return data;
}
and how im cleaning the empties
const removeEmpty = (obj:any) => {
Object.entries(obj).forEach(([key, val]) =>
(val && typeof val === 'object') && removeEmpty(val) ||
(val === null || val === "" || val === "Not defined") && delete obj[key]
);
return obj;
};
// eslint-disable-next-line consistent-return
export async function getDeviceInfo() {
try {
const devData:any = await userData.get('deviceInfo.info');
if (devData) {
// eslint-disable-next-line no-return-assign
const o = await removeEmpty(devData);
return o;
}
} catch (error) {
return error;
}
}
eqoram
09/25/2022, 2:57 PMjdgamble555
09/25/2022, 3:38 PMhearts
- pid (fk to posts.id)
- uid (fk to users.id)
(pk = pid + uid)
I have set up my rules so that only a user can like their own post. Basically all CRUD operations. However, I need ANYONE to be able to count the likes for a post.
Current Rule
sql
(role() = 'authenticated'::text)
AND (uid = uid())
AND (uid() = (SELECT posts.author FROM posts WHERE (posts.id = hearts.pid)))
Count Query
typescript
// pid is the post id
const q2 = supabase.from('hearts')
.select('pid', { count: 'exact' })
.eq('pid', pid);
How can I create a rule allowing anyone to be able to ONLY count the total likes, just not CRUD them? Can I do this with an additional rule, or do I need to edit the current one?
Thanks,
JHunterAndersonX
09/25/2022, 3:57 PM{
"dependencies": {
"@supabase/auth-helpers-nextjs": "^0.2.8",
"@supabase/auth-helpers-react": "^0.2.4",
"@supabase/supabase-js": "^1.35.7",
"@supabase/ui": "^0.36.5",
"next": "12.3.1",
"pocketbase": "^0.7.1",
"react": "17.0.2",
"react-dom": "17.0.2"
},
}
appixel
09/25/2022, 4:39 PMts
import { useQuery } from '@tanstack/react-query';
import supabase from './supabase';
import { Listing } from './types';
export async function getListings() {
const query = `
id,
title,
price,
photos,
seller: profiles (id, name, city, state),
categories (name, slug)
`;
return supabase.from<Listing>('listings').select(query);
}
export const useGetListings = () => {
return useQuery(['home', 'listings'], () => getListings());
};
Using V2 as instructed in the docs but does not work
ts
import { useQuery } from '@tanstack/react-query';
import supabase from './supabase';
import type { Database } from './database.types';
export async function getListings() {
const response = await supabase.from('listings').select(`
id,
title,
price,
photos,
seller: profiles (id, name, city, state),
categories (name, slug)
`);
return response;
}
export const useGetListings = () => {
return useQuery(['home', 'listings'], () => getListings());
};
type profiles = Database['public']['Tables']['profiles']['Row'];
type ListingsResponse = Awaited<ReturnType<typeof getListings>>;
export type ListingsResponseSuccess = ListingsResponse['data'] & {
seller: profiles;
};
enyo
09/25/2022, 4:44 PMDevThoughts
09/25/2022, 4:56 PMAnimeDev
09/25/2022, 5:08 PM0xdunston
09/25/2022, 5:12 PMfollow_by
and twit_id
of the record I want to add
let { data, error } = await supabase
.from('new-follows')
.select('username,follow_by,twit_id')
.eq('follow_by', String(follow_by))
.eq('twit_id', String(twit_id));
I run that on each record I want to add and if they return nothing then I proceed with inserting new records:
let { data, error } = await supabase
.from('new-follows')
.insert(followsTostore);
if (error) {
throw new Error(error.message);
}
return data;
Doing that first query for each record I potentially want to add really adds up though! 😦
Is there another way? Can I create some sort of table policy or edge function so I don't have to the first query for each new record?tales
09/25/2022, 5:59 PMinsert into batch (id, batch_log) VALUES (default, "test-log");
Failed to run sql query: column "test-log" does not exist
test-log
exists in the other table
**row in image manually insertedKickSquare
09/25/2022, 6:40 PMzenny.eth
09/25/2022, 7:08 PMTZUZ
09/25/2022, 8:50 PMsemipiccolo
09/25/2022, 9:41 PMNotThatBot
09/25/2022, 10:58 PM((()))
09/26/2022, 12:39 AMXzight
09/26/2022, 1:17 AMtasks
variable to an interface Task[]
?
js
const { data: tasks, error: taskError } = await supabase
.from("tasks")
.select(
`id, title, description, priority, due_by, is_completed, tags (title, id)`
);
lawrence
09/26/2022, 1:21 AMHunterAndersonX
09/26/2022, 1:38 AMUser
and Projects
(stored in Members
). I can't seem to figure it out, any ideas?매튜
09/26/2022, 3:27 AMUnfocused
09/26/2022, 3:38 AMHomemadesteam58
09/26/2022, 5:07 AMauthStateChange
event hasn't fired. Is this event fired on page load or am I missing something?
Help would be greatly appreciated.jxyz
09/26/2022, 6:22 AMpsteinroe
09/26/2022, 8:14 AM3dyuval
09/26/2022, 9:17 AMricogallo
09/26/2022, 11:14 AMsupabase db reset
unfortunately they are not found. Any idea why is this happening? I am guessing there is some transaction logic involved?gantiplex
09/26/2022, 11:20 AMpsql -d localdb < database-dump.sql
results in attached, what am I missing in the documentation?Johnny Robert
09/26/2022, 12:23 PMWORLDS BEYOND | DARREN
09/26/2022, 1:06 PMbegin
WITH users AS (
insert into public.users (id) values (new.id) returning new
),
org AS (
insert into public.org ( name) values (name ->> 'My first Org') returning name
)
insert into public.org_users (user_id, org_id)
select users.id, org.id from public.users, public.org;
return NULL;
end;
When using this function I get There is a column named "name" in table "org", but it cannot be referenced from this part of the query.
in the Postgres Logs.