1
1
2
+ -- REQUIRE: src/schema.sql
2
3
-- REQUIRE: src/encrypted/types.sql
3
4
-- REQUIRE: src/encrypted/functions.sql
4
5
5
6
6
-
7
+ --
8
+ -- The -> operator returns an encrypted matching the selector
9
+ -- Encypted JSON is a StructredVec.
10
+ -- The index term is an array of encrypteds each with ciphertext, selector and an ore cllw index term
11
+ -- {
12
+ -- "sv": [ {"c": "", "s": "", "oc": "" } ]
13
+ -- }
14
+ --
7
15
DROP OPERATOR IF EXISTS - > (eql_v1_encrypted, text );
16
+
8
17
DROP FUNCTION IF EXISTS eql_v1." ->" (e eql_v1_encrypted, selector text );
9
18
10
- --
11
- -- Returns
12
- --
13
19
CREATE FUNCTION eql_v1 ." ->" (e eql_v1_encrypted, selector text )
14
20
RETURNS eql_v1_encrypted
15
21
IMMUTABLE STRICT PARALLEL SAFE
16
22
AS $$
17
- -- DECLARE
18
- -- j jsonb;
19
- -- found: text;
20
- -- ignored: text;
23
+ DECLARE
24
+ vec jsonb;
25
+ found text ;
26
+ ignored text ;
21
27
BEGIN
28
+ -- Parent StructuredVec data
29
+ vec := eql_v1 .ste_vec (e .data );
22
30
23
- -- j := e->'j';
24
- -- PERFORM eql_v1.log(j);
31
+ RETURN (
32
+ SELECT ROW(elem)
33
+ FROM jsonb_array_elements(vec) AS elem
34
+ WHERE eql_v1 .selector (elem) = selector
35
+ LIMIT 1
36
+ );
25
37
26
- -- FOR i IN 1..jsonb_array_length(j, 1) LOOP
27
- -- -- -- The ELSE part is to help ensure constant time operation.
28
- -- -- -- The result is thrown away.
29
- -- IF j[i]->'s' = selector THEN
30
- -- found := j[i]->'c';
38
+ --
39
+ -- Constant time version
40
+ --
41
+ -- FOR i IN 0..jsonb_array_length(vec) LOOP
42
+ -- IF vec->i->>'s' = selector THEN
43
+ -- found := eql_v1.ciphertext(vec->i);
31
44
-- ELSE
32
- -- ignored := j[i]->'c' ;
45
+ -- ignored := eql_v1.ciphertext(vec->i) ;
33
46
-- END IF;
34
47
-- END LOOP;
35
48
@@ -39,52 +52,14 @@ AS $$
39
52
-- RETURN NULL;
40
53
-- END IF;
41
54
42
- RETURN (
43
- SELECT elem::eql_v1_encrypted
44
- FROM jsonb_array_elements(e .data - > ' j' ) AS elem
45
- WHERE elem- >> ' s' = selector
46
- LIMIT 1
47
- );
48
-
49
55
END;
50
56
$$ LANGUAGE plpgsql;
51
57
52
58
59
+
53
60
CREATE OPERATOR - > (
54
61
FUNCTION= eql_v1." ->" ,
55
62
LEFTARG= eql_v1_encrypted,
56
63
RIGHTARG= text
57
64
);
58
65
59
-
60
- -- ste_vec_index := eql_v1.ste_vec(col);
61
-
62
- -- IF ste_vec_index IS NULL THEN
63
- -- RETURN NULL;
64
- -- END IF;
65
-
66
- -- target_selector := selector->>'svs';
67
-
68
- -- FOR i IN 1..array_length(ste_vec_index.entries, 1) LOOP
69
- -- -- The ELSE part is to help ensure constant time operation.
70
- -- -- The result is thrown away.
71
- -- IF ste_vec_index.entries[i].tokenized_selector = target_selector THEN
72
- -- found := ste_vec_index.entries[i].ciphertext;
73
- -- ELSE
74
- -- ignored := ste_vec_index.entries[i].ciphertext;
75
- -- END IF;
76
- -- END LOOP;
77
-
78
- -- IF found IS NOT NULL THEN
79
- -- RETURN jsonb_build_object(
80
- -- 'k', 'ct',
81
- -- 'c', found,
82
- -- 'o', NULL,
83
- -- 'm', NULL,
84
- -- 'u', NULL,
85
- -- 'i', col->'i',
86
- -- 'v', 1
87
- -- );
88
- -- ELSE
89
- -- RETURN NULL;
90
- -- END IF;
0 commit comments