This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Alternatives: postgres:15-alpine | |
ARG BASE_IMAGE=postgis/postgis:15-3.4-alpine | |
## Custom Alpine Postgres docker file with custom extensions | |
FROM ${BASE_IMAGE} as builder | |
# Install required dependencies | |
RUN apk --no-cache add \ | |
python3 \ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Import the serve function to start a Deno server | |
import { serve } from "std/server"; | |
// Import pipeline utility from Hugging Face Transformers | |
import { pipeline } from "transformers"; | |
// Import Supabase client | |
import { createClient } from "supabase/client"; | |
// Shared CORS headers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare module "jdatas" { | |
function ID(cod: number): Promise<string>; | |
class File { | |
direct: string; | |
constructor(path: string, name: string); | |
create<T extends object>(data: T, encoding: string): Promise<T>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create or replace function public.gen_id() | |
returns text as $$ | |
declare | |
chars text := 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; | |
max_multiple integer := floor(256 / char_length(chars)) * char_length(chars); | |
i integer; | |
auto_id text := ''; | |
target_length integer := 20; | |
bytes bytea; | |
begin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Tested on PostgreSQL 15.1. | |
-- https://gist.github.com/srfrog/ef8c9a3a4282b865fb93f429d671d63b | |
-- https://github.com/paralleldrive/cuid2 56c54483bd7d5dd12343211c14588265e00f0887 | |
CREATE SEQUENCE IF NOT EXISTS "cuid2_seq"; | |
CREATE OR REPLACE FUNCTION _counter() RETURNS VARCHAR AS $$ | |
DECLARE | |
val bigint; | |
BEGIN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Define audit_logs table | |
CREATE TABLE IF NOT EXISTS public.audit_logs | |
( | |
uuid uuid NOT NULL, | |
operation character varying(10) COLLATE pg_catalog."default" NOT NULL, | |
userid text COLLATE pg_catalog."default" NOT NULL, | |
tablename text COLLATE pg_catalog."default" NOT NULL, | |
changed json NOT NULL, | |
stamp timestamp without time zone NOT NULL | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"os" | |
"fmt" | |
"time" | |
"io" | |
"io/ioutil" | |
"sync" | |
"log" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION jsonb_set_deep(target jsonb, path text[], val jsonb) | |
RETURNS jsonb AS $$ | |
DECLARE | |
k text; | |
p text[]; | |
BEGIN | |
IF (path = '{}') THEN | |
RETURN val; | |
ELSE | |
IF (target IS NULL) THEN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- from https://medium.com/hootsuite-engineering/recursively-merging-jsonb-in-postgresql-efd787c9fad7 | |
-- with unique array values merge | |
CREATE OR REPLACE FUNCTION jsonb_recursive_merge(A jsonb, B jsonb) | |
RETURNS jsonb LANGUAGE SQL AS $$ | |
SELECT | |
jsonb_object_agg( | |
coalesce(ka, kb), | |
CASE | |
WHEN va isnull THEN vb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE FUNCTION jsonb_replace_by_key(obj jsonb, search text, substitute jsonb) RETURNS jsonb | |
STRICT LANGUAGE SQL AS $$ | |
SELECT CASE jsonb_typeof(obj) | |
WHEN 'object' THEN | |
(SELECT coalesce(jsonb_object_agg(key, CASE WHEN key = search | |
THEN substitute | |
ELSE jsonb_replace_by_key(value, search, substitute) | |
END), '{}'::jsonb) | |
FROM jsonb_each(obj)) | |
WHEN 'array' THEN |
NewerOlder