@freehour/supabase-core 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +22 -0
- package/dist/data-service.d.ts +3136 -0
- package/dist/data-service.d.ts.map +1 -0
- package/dist/database-service.d.ts +21 -0
- package/dist/database-service.d.ts.map +1 -0
- package/dist/database.d.ts +96 -0
- package/dist/database.d.ts.map +1 -0
- package/dist/errors.d.ts +116 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/filter.d.ts +157 -0
- package/dist/filter.d.ts.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +695 -0
- package/dist/json.d.ts +4 -0
- package/dist/json.d.ts.map +1 -0
- package/dist/postgrest-extensions.d.ts +180 -0
- package/dist/postgrest-extensions.d.ts.map +1 -0
- package/dist/relation.d.ts +29 -0
- package/dist/relation.d.ts.map +1 -0
- package/dist/select.d.ts +26 -0
- package/dist/select.d.ts.map +1 -0
- package/dist/storage-service.d.ts +73 -0
- package/dist/storage-service.d.ts.map +1 -0
- package/dist/storage.d.ts +20 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/utils.d.ts +66 -0
- package/dist/utils.d.ts.map +1 -0
- package/package.json +53 -0
- package/scripts/copy-supabase-assets.js +36 -0
- package/supabase/migrations/0000_supabase_core.sql +58 -0
- package/supabase/schemas/supabase-core/1_schemas.sql +11 -0
- package/supabase/schemas/supabase-core/2_extensions.sql +5 -0
- package/supabase/schemas/supabase-core/3_functions.sql +57 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
-- Function to perform a fuzzy search on a specified table and column.
|
|
2
|
+
-- It returns records where the similarity score exceeds a specified threshold (optional).
|
|
3
|
+
-- The results are ordered by similarity score in descending order.
|
|
4
|
+
CREATE OR REPLACE FUNCTION core.fuzzy_search(
|
|
5
|
+
relation text, -- The name of the table or view to search
|
|
6
|
+
column_name text,
|
|
7
|
+
search_term text,
|
|
8
|
+
schema_name text DEFAULT 'public',
|
|
9
|
+
min_similarity float DEFAULT 0,
|
|
10
|
+
limit_results int DEFAULT 64
|
|
11
|
+
)
|
|
12
|
+
RETURNS SETOF json
|
|
13
|
+
SET search_path = ''
|
|
14
|
+
AS $$
|
|
15
|
+
DECLARE
|
|
16
|
+
query text;
|
|
17
|
+
BEGIN
|
|
18
|
+
IF search_term = '' THEN
|
|
19
|
+
query := format(
|
|
20
|
+
$q$
|
|
21
|
+
SELECT row_to_json(t) AS result
|
|
22
|
+
FROM (
|
|
23
|
+
SELECT *
|
|
24
|
+
FROM %I.%I
|
|
25
|
+
LIMIT %s
|
|
26
|
+
) t
|
|
27
|
+
$q$,
|
|
28
|
+
schema_name,
|
|
29
|
+
relation,
|
|
30
|
+
limit_results
|
|
31
|
+
);
|
|
32
|
+
ELSE
|
|
33
|
+
query := format(
|
|
34
|
+
$q$
|
|
35
|
+
SELECT row_to_json(t) AS result
|
|
36
|
+
FROM (
|
|
37
|
+
SELECT *
|
|
38
|
+
FROM (
|
|
39
|
+
SELECT *, extensions.similarity(lower(%I), lower(%L)) AS score
|
|
40
|
+
FROM %I.%I
|
|
41
|
+
) s
|
|
42
|
+
WHERE score > %s
|
|
43
|
+
ORDER BY score DESC
|
|
44
|
+
LIMIT %s
|
|
45
|
+
) t
|
|
46
|
+
$q$,
|
|
47
|
+
column_name,
|
|
48
|
+
search_term,
|
|
49
|
+
schema_name,
|
|
50
|
+
relation,
|
|
51
|
+
min_similarity,
|
|
52
|
+
limit_results
|
|
53
|
+
);
|
|
54
|
+
END IF;
|
|
55
|
+
RETURN QUERY EXECUTE query;
|
|
56
|
+
END;
|
|
57
|
+
$$ LANGUAGE plpgsql STABLE;
|