标签: supabase

Supabase JSON 查询 JavaScript

我试图从包含 JSONB 对象数组的表中获取单个条目。我可以以某种方式匹配该数组来找到所需的结果吗?

[
    {
        "chats": [
            { "id":  56789 },
            { "id":  66753 },
        ],
        "id": 999
    },  
    {
        "chats": [
            { "id":  43532 }
        ],
        "id": 999
    }
]
Run Code Online (Sandbox Code Playgroud)

我想获取与 id 匹配999并包含在chats->中的对象id: 66753

尝试了几种方法但没有奏效。

我虽然有些链接会起作用。但没有成功

let { data, error } = await supabase
  .from('xyz')
  .select('*')
  .eq('id', 999)
  .contains('chats', {id: 66753})
Run Code Online (Sandbox Code Playgroud)

能做到吗?

javascript node.js supabase

2
推荐指数
1
解决办法
5251
查看次数

Supabase如何查询同一个表两次

我最近一直在尝试 Supabase,并尝试制作一个类似 Twitter 的“回复@user”评论功能。

因此,我在下面附加了一个数据库 ERD 供参考,正如您所看到的,每个评论都有一个用户 ID 和一个“replyingTo”,它还存储正在回复的评论的用户 ID。

现在我可以在这两个表之间单独查询,因此我可以非常轻松地获取评论的用户以及评论,但是,当我尝试获取评论创建者的用户个人资料和replyingTo的个人资料时,我收到以下错误 -

Could not embed because more than one relationship was found for 'Comments' and 'profiles'
Run Code Online (Sandbox Code Playgroud)

我对 PostgreSQL 不太有经验,所以我不知道如何做这个范围的事情,这是我当前使用的以下代码,它给了我上面描述的错误。

                 const { data, error } = await supabase
                .from('Comments')
                .select('ReplyingTo, profiles:profiles(id), profiles:profiles(id)')
                .eq('commentid', cmtid)
Run Code Online (Sandbox Code Playgroud)

我的预期结果是获取评论、创建评论的用户个人资料以及收到回复的用户的个人资料。

感谢您的时间和耐心。

数据库ERD

postgresql supabase

2
推荐指数
1
解决办法
1586
查看次数

如何在flutter中获取supabase存储中上传媒体的url?

在颤振中根据文档上传图像是

final avatarFile = File('path/to/file');
final response = await supabase
  .storage
  .from('avatars')
  .upload('public/avatar1.png', avatarFile, fileOptions: FileOptions(
    cacheControl: '3600',
    upsert: false
  ));
Run Code Online (Sandbox Code Playgroud)

那么,我们如何获取这个上传媒体的downloadUrl呢?

flutter supabase supabase-database

2
推荐指数
1
解决办法
5173
查看次数

我无法让 Supabase 实时监听 Postgres 更改来工作

受到Supabase 文档的启发,我在 React Native 应用程序中有以下代码:

useEffect(() => {
  if (session?.user?.id === null) return
  const channel = supabase
    .channel('value-db-changes', { selfBroadcast: true })
    .on(
      'postgres_changes',
      {
        event: 'UPDATE',
        schema: 'public',
        table: 'messages',
        filter: `user_id=${session?.user?.id}`
      },
      (payload) => console.log('Supabase change', payload)
    )
    ?.subscribe()
}, [session?.user?.id])
Run Code Online (Sandbox Code Playgroud)

VSCode 警告我,当我编辑数据库中的行时,永远不会显示Property 'subscribe' does not exist on type 'never'console.log

supabase supabase-database

2
推荐指数
1
解决办法
3173
查看次数

supabase:“prisma migrate dev”有时会超时(postgres 建议锁)

我有一个supabase数据库(postgres 15.1.0.88)并且我使用prisma作为ORM(最新版本prisma@4.15.0)。当尝试使用 来应用迁移时prisma migrate dev,该命令大多数时候会返回一条超时错误消息:Timed out trying to acquire a postgres advisory lock

pnpm prisma migrate dev结果是:

Error: Error: P1002

The database server at `db.***.supabase.co`:`5432` was reached but timed out.

Please try again.

Please make sure your database server is running at `db.***.supabase.co`:`5432`.

Context: Timed out trying to acquire a postgres advisory lock (SELECT pg_advisory_lock(72707369)). Elapsed: 10000ms. See https://pris.ly/d/migrate-advisory-locking for details.
Run Code Online (Sandbox Code Playgroud)

在 supabase 的日志中,我也收到此错误消息,但不确定它是否与我的错误有关:

Event message
relation "_prisma_migrations" does not exist
Severity
ERROR

Timestamp
2023-06-11T09:48:31.165Z

Postgres …
Run Code Online (Sandbox Code Playgroud)

postgresql timeout prisma supabase

2
推荐指数
1
解决办法
1557
查看次数

有没有办法用 remix.run 生成 pdf

在 netlify 上托管 remix 应用程序,使用 supabase 作为数据库。有没有办法使用 remix 生成 pdf 文档?

pdf pdf-generation supabase remix.run

1
推荐指数
1
解决办法
2372
查看次数

Supabase 连接和嵌套选择

假设我有 3 张表:

  • 表1(id,列1,列2)
  • 表2(id,col3,col4)
  • 表3(表1_id表2_id

我想要做的是将 Table1 和 Table2 连接起来,然后选择具有特定列值的行(例如 col4 == "123")

我尝试过的:

supabase.from("Table3").select(
 '''
  Table1 (
   col1,
   col2
  ),
  Table2 (
   col3,
   col4
  ),
 '''
).eq("Table2.col4", "123").execute();
Run Code Online (Sandbox Code Playgroud)

这样做的问题是,对于与查询匹配的行,它返回具有 Table1 和 Table2 属性的正确对象,但对于与查询不匹配的行(因此不应返回),它返回具有 Table1 属性和 Table2 的对象属性设置为 null。

上述查询的示例:

表 1 |id | 第 1 列 | 列2| |---|------|-----| |1 | 值1 | 值2| |2 | 值3 | 值4|

表2 |id | 第 3 栏 | 第 4 栏 | …

dart flutter supabase supabase-database

1
推荐指数
1
解决办法
3959
查看次数

Supabase 重置电子邮件密码

我尝试在react中重置supabase的密码用户,但它说resetPasswordForEmail未定义```

 const { data, error } = await supabase.auth.api.resetPasswordForEmail(email)

    if (data) {
      console.log(data)
    }
    if (error) {
      console.log(error)
    }
  }
Run Code Online (Sandbox Code Playgroud)

我尝试运行代码,但由于我期望发送电子邮件的未定义函数,它给出了错误

reactjs supabase

1
推荐指数
1
解决办法
3207
查看次数

useState 的特例,这是什么?

我正在使用 expo + supabase 做反应本机项目。

来自其快速入门文档,( https://supabase.com/docs/guides/with-expo#launch )

import 'react-native-url-polyfill/auto'
import { useState, useEffect } from 'react'
import { supabase } from './lib/supabase'
import Auth from './components/Auth'
import Account from './components/Account'
import { View } from 'react-native'
import { Session } from '@supabase/supabase-js'

export default function App() {
  const [session, setSession] = (useState < Session) | (null > null)  // <-- what is this?

  useEffect(() => {
    setSession(supabase.auth.session())

    supabase.auth.onAuthStateChange((_event, session) => {
      setSession(session)
    })
  }, [])

  return (
    <View>
      {session …
Run Code Online (Sandbox Code Playgroud)

reactjs react-native supabase

0
推荐指数
1
解决办法
162
查看次数

无法部署 Supabase Edge 功能(Stripe) - 相对导入路径“http”不以 / 或 ./ 或 ../ 为前缀

我尝试通过 Supabase 的 Edge Functions 连接到 Stripe,但我不断收到此错误:

相对导入路径“http”不以 / 或 ./ 或 ../ 为前缀

我一直在挖掘,它似乎与从 Typescript 到 Javascript 的捆绑有关,但我还没有找到解决方案。

我的代码和官方的一样: https: //github.com/supabase/supabase/blob/master/examples/edge-functions/supabase/functions/stripe-webhooks/index.ts

我注意到,如果删除 Stripe 导入,我可以进行部署,所以我猜它可能是相关的,但我无法理解为什么,因为其他导入(例如 Deno 的 Supabase 导入)可以正常工作。

谢谢!!

import { serve } from 'https://deno.land/std@0.132.0/http/server.ts'

// esm.sh is used to compile stripe-node to be compatible with ES modules.
import Stripe from 'https://esm.sh/stripe@10.13.0?target=deno&deno-std=0.132.0'

const stripe = Stripe(Deno.env.get('STRIPE_API_KEY'), {
  // This is needed to use the Fetch API rather than relying on the Node http
  // package.
  httpClient: Stripe.createFetchHttpClient(),
})
// …
Run Code Online (Sandbox Code Playgroud)

stripe-payments deno supabase

0
推荐指数
1
解决办法
589
查看次数