use bigserial for user_id on entries, update SimilarEntries to include headline
This commit is contained in:
parent
aa44137660
commit
9ed951eda0
@ -19,10 +19,14 @@ DELETE FROM entries
|
||||
WHERE entry_id = $1;
|
||||
|
||||
-- name: SimilarEntries :many
|
||||
SELECT entry_id, similarity(body, $1) AS sml
|
||||
FROM entries
|
||||
WHERE body % $1
|
||||
ORDER BY sml DESC, body;
|
||||
SELECT entry_id, similarity(body, $2) as similarity,
|
||||
ts_headline('english', body, q) as headline,
|
||||
title from entries,
|
||||
plainto_tsquery($2) q
|
||||
WHERE user_id = $1 and
|
||||
similarity(body, $2) > 0.0
|
||||
order by similarity DESC
|
||||
LIMIT 10;
|
||||
|
||||
-- name: CreateUser :one
|
||||
INSERT INTO users (
|
||||
|
@ -18,15 +18,15 @@ CREATE TABLE users (
|
||||
);
|
||||
|
||||
CREATE TABLE entries (
|
||||
entry_id UUID NOT NULL default gen_random_uuid() PRIMARY KEY,
|
||||
user_id int NOT NULL REFERENCES users ON DELETE CASCADE,
|
||||
entry_id UUID NOT NULL default gen_random_uuid() PRIMARY KEY UNIQUE,
|
||||
user_id BIGSERIAL NOT NULL REFERENCES users ON DELETE CASCADE,
|
||||
created_at timestamp NOT NULL DEFAULT NOW(),
|
||||
updated_at timestamp,
|
||||
title text NOT NULL DEFAULT '',
|
||||
body text NOT NULL DEFAULT ''
|
||||
);
|
||||
|
||||
CREATE INDEX body_idx ON entries USING GIN (body gin_trgm_ops);
|
||||
CREATE INDEX body_trgm_idx ON entries USING gist (body gist_trgm_ops);
|
||||
|
||||
CREATE OR REPLACE FUNCTION hash(password text) RETURNS text AS $$
|
||||
SELECT crypt(password, gen_salt('bf', 10));
|
||||
|
Loading…
Reference in New Issue
Block a user