目标要高,因为“胆小的人和勇敢的人一样容易被抓住” —— 海伦·凯勒
Deno - Edge Functions
Key Points
1. Database Function
1.4 How to create one database function
1.4.1 One simple function
- 1
- 2
- 3
- 4
- 5
- 6
- 7
create or replace function hello_world() -- 1
returns text -- 2
language sql -- 3
as $$ -- 4
select 'hello world'; -- 5
$$; --6
COPY
At it's most basic a function has the following parts:
- create or replace function hello_world(): The function declaration, where hello_world is the name of the function. You can use either create when creating a new function or replace when replacing an existing function. Or you can use create or replace together to handle either.
- returns text: The type of data that the function returns. If it returns nothing, you can returns void.
- language sql: The language used inside the function body. This can also be a procedural language: plpgsql, plv8, plpython, etc.
- as $$: The function wrapper. Anything enclosed inside the $$ symbols will be part of the function body.
- select 'hello world';: A simple function body. The final select statement inside a function body will be returned if there are no statements following it.
- $$;: The closing symbols of the function wrapper.
2. Database Functions vs Edge Functions
For data-intensive operations, use Database Functions, which are executed within your database and can be called remotely using the REST and GraphQL API.
For use-cases which require low-latency, use Edge Functions, which are globally-distributed and can be written in Typescript.
FAQs - for self-hosting
1. The schema must be one of the following: public, storage, graphql_public
1.1 error info:
- 1
- 2
- 3
- 4
- 5
- 6
{
"code": "PGRST106",
"details": null,
"hint": null,
"message": "The schema must be one of the following: public, storage, graphql_public"
}
COPY
1.2 solutions
- To config api.schemas in config.toml file, #issues - 18444
2. AI Relevant
2.1 How to set open ai key in .env file?
- You'll need to provide your own OPENAI_KEY in your env file. (Note Open AI is expecting the default OPENAI_API_KEY, but in our code we've renamed it OPENAI_KEY, so that's what you'll have to name yours as well.) #issues - 21621
3. Using Custom Schemas
Appendix
- deno installion - https://docs.deno.com/runtime/getting_started/installation/
- jsr.io - https://jsr.io/
- esm.sh - https://esm.sh/
Create modern(es2015+) web apps easily with NPM packages in browser/deno.
评论区
写评论
登录
所以,就随便说点什么吧...
这里什么都没有,快来评论吧...