@@ -54,152 +54,6 @@ CREATE SCHEMA library;
5454
5555ALTER SCHEMA library OWNER TO postgres;
5656
57- --
58- -- TOC entry 244 (class 1255 OID 16551)
59- -- Name: generate_random_street(); Type: FUNCTION; Schema: library; Owner: postgres
60- --
61-
62- CREATE FUNCTION library.generate_random_street() RETURNS text
63- LANGUAGE plpgsql
64- AS $$
65- DECLARE
66- street_names TEXT[] := ARRAY['Main St', 'Oak Ave', 'Pine Ln', 'Maple Dr', '1st St', '2nd Ave', 'High St', 'Low St', 'River Rd', 'Hillside Ct'];
67- BEGIN
68- RETURN street_names[floor(random() * array_length(street_names, 1)) + 1] || ' ' || (floor(random() * 1000) + 1);
69- END;
70- $$;
71-
72-
73- ALTER FUNCTION library.generate_random_street() OWNER TO postgres;
74-
75- --
76- -- TOC entry 245 (class 1255 OID 16552)
77- -- Name: generate_random_tags(); Type: FUNCTION; Schema: library; Owner: postgres
78- --
79-
80- CREATE FUNCTION library.generate_random_tags() RETURNS text
81- LANGUAGE plpgsql
82- AS $$
83- DECLARE
84- possible_tags TEXT[] := ARRAY[
85- 'club pick', 'reading challenge', 'recommended read', 'must read', 'favorite', 'booktok', 'bookstagram',
86- 'hangover', 'currently reading', 'tbr', 'haul', 'shelfie', 'worm', 'bibliophile', 'lover', 'reader', 'reading',
87- 'review', 'recommendation', 'discussion', 'chat', 'community', 'ish', 'reading list', 'stack',
88- 'new release', 'bestseller', 'award winner', 'prize winner', 'classic literature', 'contemporary fiction', 'debut novel',
89- 'indie author', 'self-published', 'audio', 'e', 'hardcover', 'paperback', 'used', 'library',
90- 'signing', 'author event', 'festival', 'literary festival', 'fair', 'swap', 'exchange',
91- 'cozy read', 'beach read', 'winter read', 'summer read', 'fall read', 'spring read', 'weekend read', 'bedtime read',
92- 'quick read', 'short read', 'long read', 'slow burn', 'fast-paced', 'plot-driven', 'character-driven', 'world-building',
93- 'writing style', 'themes', 'motifs', 'symbols', 'imagery', 'metaphors', 'similes', 'allegory', 'irony', 'satire',
94- 'humor', 'drama', 'romance', 'mystery', 'thriller', 'suspense', 'horror', 'fantasy', 'science fiction',
95- 'historical fiction', 'biography', 'autobiography', 'memoir', 'essay', 'poetry', 'graphic novel', 'comic',
96- 'manga', 'childrens literature', 'young adult', 'middle grade', 'new adult', 'adult fiction', 'literary fiction',
97- 'genre fiction', 'speculative fiction', 'realistic fiction', 'historical romance', 'paranormal romance', 'urban fantasy',
98- 'high fantasy', 'low fantasy', 'magical realism', 'space opera', 'cyberpunk', 'dystopian fiction', 'utopian fiction',
99- 'apocalyptic fiction', 'post-apocalyptic fiction', 'time travel fiction', 'alternate history fiction', 'military fiction',
100- 'war fiction', 'spy fiction', 'espionage fiction', 'political thriller', 'legal thriller', 'courtroom drama', 'psychological thriller',
101- 'domestic thriller', 'gothic fiction', 'historical mystery', 'cozy mystery', 'hard-boiled detective', 'police procedural',
102- 'amateur sleuth', 'true crime', 'creative nonfiction', 'science writing', 'nature writing', 'travel writing', 'food writing',
103- 'self-help', 'business', 'technology', 'science', 'history', 'art', 'music',
104- 'photography', 'cookbook', 'guide', 'reference', 'text', 'educational', 'academic',
105- 'professional', 'technical', 'medical', 'legal', 'business', 'finance', 'real estate',
106- 'engineering', 'manufacturing', 'construction', 'agriculture', 'mining', 'energy',
107- 'transportation', 'communication', 'media', 'entertainment', 'sports', 'recreation',
108- 'travel', 'tourism', 'hospitality', 'education', 'healthcare', 'social services',
109- 'government', 'politics', 'law', 'justice', 'crime', 'security', 'defense',
110- 'international relations', 'globalization', 'development', 'sustainability',
111- 'environment', 'climate change', 'energy', 'water', 'food', 'agriculture', 'health',
112- 'wellness', 'poverty', 'inequality', 'human rights', 'democracy', 'freedom', 'justice',
113- 'peace', 'war', 'conflict', 'terrorism', 'global issues', 'social issues',
114- 'cultural issues', 'economic issues', 'political issues', 'religious issues',
115- 'philosophical issues', 'spiritual issues'
116- ]; -- No "book" in any of the tags
117-
118- num_tags INT;
119- i INT;
120- tags_string TEXT := '';
121- BEGIN
122- num_tags := floor(random() * 3) + 1; -- Generates 1 to 3 tags per book
123-
124- FOR i IN 1..num_tags LOOP
125- tags_string := tags_string || possible_tags[floor(random() * array_length(possible_tags, 1)) + 1];
126- IF i < num_tags THEN
127- tags_string := tags_string || ',';
128- END IF;
129- END LOOP;
130- RETURN tags_string;
131- END;
132- $$;
133-
134-
135- ALTER FUNCTION library.generate_random_tags() OWNER TO postgres;
136-
137- --
138- -- TOC entry 246 (class 1255 OID 16554)
139- -- Name: get_books_borrowed_by_user(integer); Type: FUNCTION; Schema: library; Owner: postgres
140- --
141-
142- CREATE FUNCTION library.get_books_borrowed_by_user(user_id_param integer)
143- RETURNS TABLE(title character varying, borrow_date timestamp without time zone, due_date timestamp without time zone, returned boolean)
144- LANGUAGE plpgsql
145- AS $function$
146- BEGIN
147- RETURN QUERY
148- SELECT b.title, ops.borrow_date, ops.due_date, ops.returned
149- FROM library.operations ops
150- JOIN library.books b ON ops.book_id = b.id
151- WHERE ops.user_id = user_id_param;
152- END;
153- $function$;
154-
155- ALTER FUNCTION library.get_books_borrowed_by_user(user_id_param integer) OWNER TO postgres;
156-
157- --
158- -- TOC entry 247 (class 1255 OID 16555)
159- -- Name: get_books_by_author(integer); Type: FUNCTION; Schema: library; Owner: postgres
160- --
161-
162- CREATE FUNCTION library.get_books_by_author(author_id_param integer)
163- RETURNS SETOF library.books
164- LANGUAGE plpgsql
165- AS $function$
166- BEGIN
167- RETURN QUERY
168- SELECT * FROM library.books b
169- WHERE b.id IN (
170- SELECT ab.book_id
171- FROM library.author_book ab
172- WHERE ab.author_id = author_id_param);
173- END
174- $function$;
175-
176-
177- ALTER FUNCTION library.get_books_by_author(author_id integer) OWNER TO postgres;
178-
179- --
180- -- TOC entry 248 (class 1255 OID 16556)
181- -- Name: get_books_by_genre(character varying); Type: FUNCTION; Schema: library; Owner: postgres
182- --
183-
184- CREATE FUNCTION library.get_books_by_genre(genre_param character varying)
185- RETURNS TABLE(title character varying)
186- LANGUAGE plpgsql
187- AS $function$
188- BEGIN
189- RETURN QUERY
190- SELECT b.title
191- FROM library.books b
192- WHERE b.id IN (
193- SELECT bg.book_id
194- FROM library.book_genre bg
195- JOIN library.genres g ON bg.genre_id = g.id
196- WHERE g.name = genre_param
197- );
198- END;
199- $function$;
200-
201-
202- ALTER FUNCTION library.get_books_by_genre(genre_param character varying) OWNER TO postgres;
20357
20458SET default_tablespace = '';
20559
@@ -98660,3 +98514,149 @@ ALTER TABLE ONLY library.reviews
9866098514-- PostgreSQL database dump complete
9866198515--
9866298516
98517+ --
98518+ -- TOC entry 244 (class 1255 OID 16551)
98519+ -- Name: generate_random_street(); Type: FUNCTION; Schema: library; Owner: postgres
98520+ --
98521+
98522+ CREATE FUNCTION library.generate_random_street() RETURNS text
98523+ LANGUAGE plpgsql
98524+ AS $$
98525+ DECLARE
98526+ street_names TEXT[] := ARRAY['Main St', 'Oak Ave', 'Pine Ln', 'Maple Dr', '1st St', '2nd Ave', 'High St', 'Low St', 'River Rd', 'Hillside Ct'];
98527+ BEGIN
98528+ RETURN street_names[floor(random() * array_length(street_names, 1)) + 1] || ' ' || (floor(random() * 1000) + 1);
98529+ END;
98530+ $$;
98531+
98532+
98533+ ALTER FUNCTION library.generate_random_street() OWNER TO postgres;
98534+
98535+ --
98536+ -- TOC entry 245 (class 1255 OID 16552)
98537+ -- Name: generate_random_tags(); Type: FUNCTION; Schema: library; Owner: postgres
98538+ --
98539+
98540+ CREATE FUNCTION library.generate_random_tags() RETURNS text
98541+ LANGUAGE plpgsql
98542+ AS $$
98543+ DECLARE
98544+ possible_tags TEXT[] := ARRAY[
98545+ 'club pick', 'reading challenge', 'recommended read', 'must read', 'favorite', 'booktok', 'bookstagram',
98546+ 'hangover', 'currently reading', 'tbr', 'haul', 'shelfie', 'worm', 'bibliophile', 'lover', 'reader', 'reading',
98547+ 'review', 'recommendation', 'discussion', 'chat', 'community', 'ish', 'reading list', 'stack',
98548+ 'new release', 'bestseller', 'award winner', 'prize winner', 'classic literature', 'contemporary fiction', 'debut novel',
98549+ 'indie author', 'self-published', 'audio', 'e', 'hardcover', 'paperback', 'used', 'library',
98550+ 'signing', 'author event', 'festival', 'literary festival', 'fair', 'swap', 'exchange',
98551+ 'cozy read', 'beach read', 'winter read', 'summer read', 'fall read', 'spring read', 'weekend read', 'bedtime read',
98552+ 'quick read', 'short read', 'long read', 'slow burn', 'fast-paced', 'plot-driven', 'character-driven', 'world-building',
98553+ 'writing style', 'themes', 'motifs', 'symbols', 'imagery', 'metaphors', 'similes', 'allegory', 'irony', 'satire',
98554+ 'humor', 'drama', 'romance', 'mystery', 'thriller', 'suspense', 'horror', 'fantasy', 'science fiction',
98555+ 'historical fiction', 'biography', 'autobiography', 'memoir', 'essay', 'poetry', 'graphic novel', 'comic',
98556+ 'manga', 'childrens literature', 'young adult', 'middle grade', 'new adult', 'adult fiction', 'literary fiction',
98557+ 'genre fiction', 'speculative fiction', 'realistic fiction', 'historical romance', 'paranormal romance', 'urban fantasy',
98558+ 'high fantasy', 'low fantasy', 'magical realism', 'space opera', 'cyberpunk', 'dystopian fiction', 'utopian fiction',
98559+ 'apocalyptic fiction', 'post-apocalyptic fiction', 'time travel fiction', 'alternate history fiction', 'military fiction',
98560+ 'war fiction', 'spy fiction', 'espionage fiction', 'political thriller', 'legal thriller', 'courtroom drama', 'psychological thriller',
98561+ 'domestic thriller', 'gothic fiction', 'historical mystery', 'cozy mystery', 'hard-boiled detective', 'police procedural',
98562+ 'amateur sleuth', 'true crime', 'creative nonfiction', 'science writing', 'nature writing', 'travel writing', 'food writing',
98563+ 'self-help', 'business', 'technology', 'science', 'history', 'art', 'music',
98564+ 'photography', 'cookbook', 'guide', 'reference', 'text', 'educational', 'academic',
98565+ 'professional', 'technical', 'medical', 'legal', 'business', 'finance', 'real estate',
98566+ 'engineering', 'manufacturing', 'construction', 'agriculture', 'mining', 'energy',
98567+ 'transportation', 'communication', 'media', 'entertainment', 'sports', 'recreation',
98568+ 'travel', 'tourism', 'hospitality', 'education', 'healthcare', 'social services',
98569+ 'government', 'politics', 'law', 'justice', 'crime', 'security', 'defense',
98570+ 'international relations', 'globalization', 'development', 'sustainability',
98571+ 'environment', 'climate change', 'energy', 'water', 'food', 'agriculture', 'health',
98572+ 'wellness', 'poverty', 'inequality', 'human rights', 'democracy', 'freedom', 'justice',
98573+ 'peace', 'war', 'conflict', 'terrorism', 'global issues', 'social issues',
98574+ 'cultural issues', 'economic issues', 'political issues', 'religious issues',
98575+ 'philosophical issues', 'spiritual issues'
98576+ ]; -- No "book" in any of the tags
98577+
98578+ num_tags INT;
98579+ i INT;
98580+ tags_string TEXT := '';
98581+ BEGIN
98582+ num_tags := floor(random() * 3) + 1; -- Generates 1 to 3 tags per book
98583+
98584+ FOR i IN 1..num_tags LOOP
98585+ tags_string := tags_string || possible_tags[floor(random() * array_length(possible_tags, 1)) + 1];
98586+ IF i < num_tags THEN
98587+ tags_string := tags_string || ',';
98588+ END IF;
98589+ END LOOP;
98590+ RETURN tags_string;
98591+ END;
98592+ $$;
98593+
98594+
98595+ ALTER FUNCTION library.generate_random_tags() OWNER TO postgres;
98596+
98597+ --
98598+ -- TOC entry 246 (class 1255 OID 16554)
98599+ -- Name: get_books_borrowed_by_user(integer); Type: FUNCTION; Schema: library; Owner: postgres
98600+ --
98601+
98602+ CREATE FUNCTION library.get_books_borrowed_by_user(user_id_param integer)
98603+ RETURNS TABLE(title character varying, borrow_date timestamp without time zone, due_date timestamp without time zone, returned boolean)
98604+ LANGUAGE plpgsql
98605+ AS $function$
98606+ BEGIN
98607+ RETURN QUERY
98608+ SELECT b.title, ops.borrow_date, ops.due_date, ops.returned
98609+ FROM library.operations ops
98610+ JOIN library.books b ON ops.book_id = b.id
98611+ WHERE ops.user_id = user_id_param;
98612+ END;
98613+ $function$;
98614+
98615+ ALTER FUNCTION library.get_books_borrowed_by_user(user_id_param integer) OWNER TO postgres;
98616+
98617+ --
98618+ -- TOC entry 247 (class 1255 OID 16555)
98619+ -- Name: get_books_by_author(integer); Type: FUNCTION; Schema: library; Owner: postgres
98620+ --
98621+
98622+ CREATE FUNCTION library.get_books_by_author(author_id_param integer)
98623+ RETURNS SETOF library.books
98624+ LANGUAGE plpgsql
98625+ AS $function$
98626+ BEGIN
98627+ RETURN QUERY
98628+ SELECT * FROM library.books b
98629+ WHERE b.id IN (
98630+ SELECT ab.book_id
98631+ FROM library.author_book ab
98632+ WHERE ab.author_id = author_id_param);
98633+ END
98634+ $function$;
98635+
98636+
98637+ ALTER FUNCTION library.get_books_by_author(author_id integer) OWNER TO postgres;
98638+
98639+ --
98640+ -- TOC entry 248 (class 1255 OID 16556)
98641+ -- Name: get_books_by_genre(character varying); Type: FUNCTION; Schema: library; Owner: postgres
98642+ --
98643+
98644+ CREATE FUNCTION library.get_books_by_genre(genre_param character varying)
98645+ RETURNS TABLE(title character varying)
98646+ LANGUAGE plpgsql
98647+ AS $function$
98648+ BEGIN
98649+ RETURN QUERY
98650+ SELECT b.title
98651+ FROM library.books b
98652+ WHERE b.id IN (
98653+ SELECT bg.book_id
98654+ FROM library.book_genre bg
98655+ JOIN library.genres g ON bg.genre_id = g.id
98656+ WHERE g.name = genre_param
98657+ );
98658+ END;
98659+ $function$;
98660+
98661+
98662+ ALTER FUNCTION library.get_books_by_genre(genre_param character varying) OWNER TO postgres;
0 commit comments