Skip to content

Commit c1f5eb9

Browse files
committed
refactor: rename add_index to add_search_term
1 parent 1ed5e8b commit c1f5eb9

File tree

5 files changed

+137
-130
lines changed

5 files changed

+137
-130
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,10 @@ In order to perform searchable operations on encrypted data, you must configure
191191
192192
### Adding an index
193193

194-
Add an index to an encrypted column using the `eql_v2.add_index` function:
194+
Add an index to an encrypted column using the `eql_v2.add_search_term` function:
195195

196196
```sql
197-
SELECT eql_v2.add_index(
197+
SELECT eql_v2.add_search_term(
198198
'table_name', -- Name of the table
199199
'column_name', -- Name of the column
200200
'index_name', -- Index kind ('unique', 'match', 'ore', 'ste_vec')
@@ -208,7 +208,7 @@ You can read more about the index configuration options [here](docs/reference/IN
208208
**Example (Unique index):**
209209

210210
```sql
211-
SELECT eql_v2.add_index(
211+
SELECT eql_v2.add_search_term(
212212
'users',
213213
'encrypted_email',
214214
'unique',
@@ -236,7 +236,7 @@ Enable equality search on encrypted data using the `eql_v2.unique` function.
236236
**Index configuration example:**
237237

238238
```sql
239-
SELECT eql_v2.add_index(
239+
SELECT eql_v2.add_search_term(
240240
'users',
241241
'encrypted_email',
242242
'unique',
@@ -266,7 +266,7 @@ Enables basic full-text search on encrypted data using the `eql_v2.match` functi
266266
**Index configuration example:**
267267

268268
```sql
269-
SELECT eql_v2.add_index(
269+
SELECT eql_v2.add_search_term(
270270
'users',
271271
'encrypted_email',
272272
'match',

src/config/config_test.sql

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
--
55
-- Helper function for assertions
66
--
7-
DROP FUNCTION IF EXISTS _index_exists(text, text, text, text);
8-
CREATE FUNCTION _index_exists(table_name text, column_name text, index_name text, state text DEFAULT 'pending')
7+
DROP FUNCTION IF EXISTS _search_config_exists(text, text, text, text);
8+
CREATE FUNCTION _search_config_exists(table_name text, column_name text, index_name text, state text DEFAULT 'pending')
99
RETURNS boolean
1010
LANGUAGE sql STRICT PARALLEL SAFE
1111
BEGIN ATOMIC
@@ -25,23 +25,23 @@ DO $$
2525
BEGIN
2626

2727
-- Add indexes
28-
PERFORM eql_v2.add_index('users', 'name', 'match');
29-
ASSERT (SELECT _index_exists('users', 'name', 'match'));
28+
PERFORM eql_v2.add_search_config('users', 'name', 'match');
29+
ASSERT (SELECT _search_config_exists('users', 'name', 'match'));
3030

3131
-- Add index with cast
32-
PERFORM eql_v2.add_index('users', 'name', 'unique', 'int');
33-
ASSERT (SELECT _index_exists('users', 'name', 'unique'));
32+
PERFORM eql_v2.add_search_config('users', 'name', 'unique', 'int');
33+
ASSERT (SELECT _search_config_exists('users', 'name', 'unique'));
3434

3535
ASSERT (SELECT EXISTS (SELECT id FROM eql_v2_configuration c
3636
WHERE c.state = 'pending' AND
3737
c.data #> array['tables', 'users', 'name'] ? 'cast_as'));
3838

3939
-- Match index removed
40-
PERFORM eql_v2.remove_index('users', 'name', 'match');
41-
ASSERT NOT (SELECT _index_exists('users', 'name', 'match'));
40+
PERFORM eql_v2.remove_search_config('users', 'name', 'match');
41+
ASSERT NOT (SELECT _search_config_exists('users', 'name', 'match'));
4242

4343
-- All indexes removed, delete the emtpty pending config
44-
PERFORM eql_v2.remove_index('users', 'name', 'unique');
44+
PERFORM eql_v2.remove_search_config('users', 'name', 'unique');
4545
ASSERT (SELECT NOT EXISTS (SELECT FROM eql_v2_configuration c WHERE c.state = 'pending'));
4646

4747
END;
@@ -60,16 +60,16 @@ DO $$
6060
BEGIN
6161

6262
-- Add indexes
63-
PERFORM eql_v2.add_index('users', 'name', 'match');
64-
ASSERT (SELECT _index_exists('users', 'name', 'match'));
63+
PERFORM eql_v2.add_search_config('users', 'name', 'match');
64+
ASSERT (SELECT _search_config_exists('users', 'name', 'match'));
6565

6666
ASSERT (SELECT EXISTS (SELECT id FROM eql_v2_configuration c
6767
WHERE c.state = 'pending' AND
6868
c.data #> array['tables', 'users', 'name', 'indexes'] ? 'match'));
6969

7070
-- Add index with cast
71-
PERFORM eql_v2.add_index('blah', 'vtha', 'unique', 'int');
72-
ASSERT (SELECT _index_exists('blah', 'vtha', 'unique'));
71+
PERFORM eql_v2.add_search_config('blah', 'vtha', 'unique', 'int');
72+
ASSERT (SELECT _search_config_exists('blah', 'vtha', 'unique'));
7373

7474
ASSERT (SELECT EXISTS (SELECT id FROM eql_v2_configuration c
7575
WHERE c.state = 'pending' AND
@@ -82,12 +82,12 @@ DO $$
8282

8383

8484
-- Match index removed
85-
PERFORM eql_v2.remove_index('users', 'name', 'match');
86-
ASSERT NOT (SELECT _index_exists('users', 'name', 'match'));
85+
PERFORM eql_v2.remove_search_config('users', 'name', 'match');
86+
ASSERT NOT (SELECT _search_config_exists('users', 'name', 'match'));
8787

8888
-- Match index removed
89-
PERFORM eql_v2.remove_index('blah', 'vtha', 'unique');
90-
ASSERT NOT (SELECT _index_exists('users', 'vtha', 'unique'));
89+
PERFORM eql_v2.remove_search_config('blah', 'vtha', 'unique');
90+
ASSERT NOT (SELECT _search_config_exists('users', 'vtha', 'unique'));
9191

9292
-- All indexes removed, delete the emtpty pending config
9393
ASSERT (SELECT NOT EXISTS (SELECT FROM eql_v2_configuration c WHERE c.state = 'pending'));
@@ -107,12 +107,12 @@ $$ LANGUAGE plpgsql;
107107

108108
DO $$
109109
BEGIN
110-
PERFORM eql_v2.add_index('users', 'name', 'match');
111-
ASSERT (SELECT _index_exists('users', 'name', 'match'));
110+
PERFORM eql_v2.add_search_config('users', 'name', 'match');
111+
ASSERT (SELECT _search_config_exists('users', 'name', 'match'));
112112

113113
-- Pending configuration contains the path `user/name.match.option`
114-
PERFORM eql_v2.modify_index('users', 'name', 'match', 'int', '{"option": "value"}'::jsonb);
115-
ASSERT (SELECT _index_exists('users', 'name', 'match'));
114+
PERFORM eql_v2.modify_search_config('users', 'name', 'match', 'int', '{"option": "value"}'::jsonb);
115+
ASSERT (SELECT _search_config_exists('users', 'name', 'match'));
116116

117117
ASSERT (SELECT EXISTS (SELECT id FROM eql_v2_configuration c
118118
WHERE c.state = 'pending' AND
@@ -123,7 +123,7 @@ DO $$
123123
c.data #> array['tables', 'users', 'name'] ? 'cast_as'));
124124

125125
-- All indexes removed, delete the emtpty pending config
126-
PERFORM eql_v2.remove_index('users', 'name', 'match');
126+
PERFORM eql_v2.remove_search_config('users', 'name', 'match');
127127
ASSERT (SELECT NOT EXISTS (SELECT FROM eql_v2_configuration c WHERE c.state = 'pending'));
128128
END;
129129
$$ LANGUAGE plpgsql;
@@ -160,16 +160,16 @@ INSERT INTO eql_v2_configuration (state, data) VALUES (
160160
-- An encrypting config should exist
161161
DO $$
162162
BEGIN
163-
ASSERT (SELECT _index_exists('users', 'blah', 'match', 'active'));
163+
ASSERT (SELECT _search_config_exists('users', 'blah', 'match', 'active'));
164164

165-
PERFORM eql_v2.add_index('users', 'name', 'match');
165+
PERFORM eql_v2.add_search_config('users', 'name', 'match');
166166

167167
-- index added to name
168-
ASSERT (SELECT _index_exists('users', 'name', 'match' ));
168+
ASSERT (SELECT _search_config_exists('users', 'name', 'match' ));
169169

170170
-- pending is a copy of the active config
171171
-- and the active index still exists
172-
ASSERT (SELECT _index_exists('users', 'blah', 'match'));
172+
ASSERT (SELECT _search_config_exists('users', 'blah', 'match'));
173173

174174
END;
175175
$$ LANGUAGE plpgsql;

src/config/functions.sql

Lines changed: 8 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,16 @@
11
-- REQUIRE: src/config/types.sql
2+
-- REQUIRE: src/config/functions_private.sql
23
--
3-
-- Configuration functions
4+
-- Customer-facing configuration functions
5+
-- Depends on private functions for implemenation
46
--
57
--
68

7-
8-
CREATE FUNCTION eql_v2.config_default(config jsonb)
9-
RETURNS jsonb
10-
IMMUTABLE PARALLEL SAFE
11-
AS $$
12-
BEGIN
13-
IF config IS NULL THEN
14-
SELECT jsonb_build_object('v', 1, 'tables', jsonb_build_object()) INTO config;
15-
END IF;
16-
RETURN config;
17-
END;
18-
$$ LANGUAGE plpgsql;
19-
20-
21-
22-
CREATE FUNCTION eql_v2.config_add_table(table_name text, config jsonb)
23-
RETURNS jsonb
24-
IMMUTABLE PARALLEL SAFE
25-
AS $$
26-
DECLARE
27-
tbl jsonb;
28-
BEGIN
29-
IF NOT config #> array['tables'] ? table_name THEN
30-
SELECT jsonb_insert(config, array['tables', table_name], jsonb_build_object()) INTO config;
31-
END IF;
32-
RETURN config;
33-
END;
34-
$$ LANGUAGE plpgsql;
35-
36-
37-
-- Add the column if it doesn't exist
38-
39-
CREATE FUNCTION eql_v2.config_add_column(table_name text, column_name text, config jsonb)
40-
RETURNS jsonb
41-
IMMUTABLE PARALLEL SAFE
42-
AS $$
43-
DECLARE
44-
col jsonb;
45-
BEGIN
46-
IF NOT config #> array['tables', table_name] ? column_name THEN
47-
SELECT jsonb_build_object('indexes', jsonb_build_object()) into col;
48-
SELECT jsonb_set(config, array['tables', table_name, column_name], col) INTO config;
49-
END IF;
50-
RETURN config;
51-
END;
52-
$$ LANGUAGE plpgsql;
53-
54-
55-
-- Set the cast
56-
57-
CREATE FUNCTION eql_v2.config_add_cast(table_name text, column_name text, cast_as text, config jsonb)
58-
RETURNS jsonb
59-
IMMUTABLE PARALLEL SAFE
60-
AS $$
61-
BEGIN
62-
SELECT jsonb_set(config, array['tables', table_name, column_name, 'cast_as'], to_jsonb(cast_as)) INTO config;
63-
RETURN config;
64-
END;
65-
$$ LANGUAGE plpgsql;
66-
67-
68-
-- Add the column if it doesn't exist
69-
70-
CREATE FUNCTION eql_v2.config_add_index(table_name text, column_name text, index_name text, opts jsonb, config jsonb)
71-
RETURNS jsonb
72-
IMMUTABLE PARALLEL SAFE
73-
AS $$
74-
BEGIN
75-
SELECT jsonb_insert(config, array['tables', table_name, column_name, 'indexes', index_name], opts) INTO config;
76-
RETURN config;
77-
END;
78-
$$ LANGUAGE plpgsql;
79-
80-
81-
--
82-
-- Default options for match index
83-
--
84-
85-
CREATE FUNCTION eql_v2.config_match_default()
86-
RETURNS jsonb
87-
LANGUAGE sql STRICT PARALLEL SAFE
88-
BEGIN ATOMIC
89-
SELECT jsonb_build_object(
90-
'k', 6,
91-
'm', 2048,
92-
'include_original', true,
93-
'tokenizer', json_build_object('kind', 'ngram', 'token_length', 3),
94-
'token_filters', json_build_array(json_build_object('kind', 'downcase')));
95-
END;
96-
979
--
9810
-- Adds an index term to the configuration
9911
--
10012

101-
CREATE FUNCTION eql_v2.add_index(table_name text, column_name text, index_name text, cast_as text DEFAULT 'text', opts jsonb DEFAULT '{}')
13+
CREATE FUNCTION eql_v2.add_search_config(table_name text, column_name text, index_name text, cast_as text DEFAULT 'text', opts jsonb DEFAULT '{}')
10214
RETURNS jsonb
10315

10416
AS $$
@@ -149,7 +61,7 @@ $$ LANGUAGE plpgsql;
14961

15062

15163

152-
CREATE FUNCTION eql_v2.remove_index(table_name text, column_name text, index_name text)
64+
CREATE FUNCTION eql_v2.remove_search_config(table_name text, column_name text, index_name text)
15365
RETURNS jsonb
15466
AS $$
15567
DECLARE
@@ -209,12 +121,12 @@ $$ LANGUAGE plpgsql;
209121

210122

211123

212-
CREATE FUNCTION eql_v2.modify_index(table_name text, column_name text, index_name text, cast_as text DEFAULT 'text', opts jsonb DEFAULT '{}')
124+
CREATE FUNCTION eql_v2.modify_search_config(table_name text, column_name text, index_name text, cast_as text DEFAULT 'text', opts jsonb DEFAULT '{}')
213125
RETURNS jsonb
214126
AS $$
215127
BEGIN
216-
PERFORM eql_v2.remove_index(table_name, column_name, index_name);
217-
RETURN eql_v2.add_index(table_name, column_name, index_name, cast_as, opts);
128+
PERFORM eql_v2.remove_search_config(table_name, column_name, index_name);
129+
RETURN eql_v2.add_search_config(table_name, column_name, index_name, cast_as, opts);
218130
END;
219131
$$ LANGUAGE plpgsql;
220132

src/config/functions_private.sql

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
-- REQUIRE: src/config/types.sql
2+
--
3+
-- Private configuration functions
4+
-- Internal implemention details that customers should not need to worry about.
5+
--
6+
--
7+
8+
CREATE FUNCTION eql_v2.config_default(config jsonb)
9+
RETURNS jsonb
10+
IMMUTABLE PARALLEL SAFE
11+
AS $$
12+
BEGIN
13+
IF config IS NULL THEN
14+
SELECT jsonb_build_object('v', 1, 'tables', jsonb_build_object()) INTO config;
15+
END IF;
16+
RETURN config;
17+
END;
18+
$$ LANGUAGE plpgsql;
19+
20+
21+
22+
CREATE FUNCTION eql_v2.config_add_table(table_name text, config jsonb)
23+
RETURNS jsonb
24+
IMMUTABLE PARALLEL SAFE
25+
AS $$
26+
DECLARE
27+
tbl jsonb;
28+
BEGIN
29+
IF NOT config #> array['tables'] ? table_name THEN
30+
SELECT jsonb_insert(config, array['tables', table_name], jsonb_build_object()) INTO config;
31+
END IF;
32+
RETURN config;
33+
END;
34+
$$ LANGUAGE plpgsql;
35+
36+
37+
-- Add the column if it doesn't exist
38+
39+
CREATE FUNCTION eql_v2.config_add_column(table_name text, column_name text, config jsonb)
40+
RETURNS jsonb
41+
IMMUTABLE PARALLEL SAFE
42+
AS $$
43+
DECLARE
44+
col jsonb;
45+
BEGIN
46+
IF NOT config #> array['tables', table_name] ? column_name THEN
47+
SELECT jsonb_build_object('indexes', jsonb_build_object()) into col;
48+
SELECT jsonb_set(config, array['tables', table_name, column_name], col) INTO config;
49+
END IF;
50+
RETURN config;
51+
END;
52+
$$ LANGUAGE plpgsql;
53+
54+
55+
-- Set the cast
56+
57+
CREATE FUNCTION eql_v2.config_add_cast(table_name text, column_name text, cast_as text, config jsonb)
58+
RETURNS jsonb
59+
IMMUTABLE PARALLEL SAFE
60+
AS $$
61+
BEGIN
62+
SELECT jsonb_set(config, array['tables', table_name, column_name, 'cast_as'], to_jsonb(cast_as)) INTO config;
63+
RETURN config;
64+
END;
65+
$$ LANGUAGE plpgsql;
66+
67+
68+
-- Add the column if it doesn't exist
69+
70+
CREATE FUNCTION eql_v2.config_add_index(table_name text, column_name text, index_name text, opts jsonb, config jsonb)
71+
RETURNS jsonb
72+
IMMUTABLE PARALLEL SAFE
73+
AS $$
74+
BEGIN
75+
SELECT jsonb_insert(config, array['tables', table_name, column_name, 'indexes', index_name], opts) INTO config;
76+
RETURN config;
77+
END;
78+
$$ LANGUAGE plpgsql;
79+
80+
81+
--
82+
-- Default options for match index
83+
--
84+
85+
CREATE FUNCTION eql_v2.config_match_default()
86+
RETURNS jsonb
87+
LANGUAGE sql STRICT PARALLEL SAFE
88+
BEGIN ATOMIC
89+
SELECT jsonb_build_object(
90+
'k', 6,
91+
'm', 2048,
92+
'include_original', true,
93+
'tokenizer', json_build_object('kind', 'ngram', 'token_length', 3),
94+
'token_filters', json_build_array(json_build_object('kind', 'downcase')));
95+
END;

0 commit comments

Comments
 (0)