diff --git a/.sqlx/query-0644481879afc3abad9188fde0b00d19638ff16d6c8678d8d4e54a4b6bf5393d.json b/.sqlx/query-0644481879afc3abad9188fde0b00d19638ff16d6c8678d8d4e54a4b6bf5393d.json deleted file mode 100644 index 693a99f..0000000 --- a/.sqlx/query-0644481879afc3abad9188fde0b00d19638ff16d6c8678d8d4e54a4b6bf5393d.json +++ /dev/null @@ -1,85 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "\n SELECT\n b.id,\n b.title,\n b.lang,\n b.file_type,\n b.year,\n CASE WHEN b.file_type = 'fb2' THEN ARRAY['fb2', 'epub', 'mobi', 'fb2zip']::text[] ELSE ARRAY[b.file_type]::text[] END AS \"available_types!: Vec\",\n b.uploaded,\n (\n SELECT\n JSONB_AGG(\n JSONB_BUILD_OBJECT(\n 'id', authors.id,\n 'first_name', authors.first_name,\n 'last_name', authors.last_name,\n 'middle_name', authors.middle_name,\n 'annotation_exists', EXISTS(\n SELECT * FROM author_annotations WHERE author = authors.id\n )\n )\n )\n FROM book_authors\n JOIN authors ON authors.id = book_authors.author\n WHERE book_authors.book = b.id\n ) AS \"authors!: Vec\",\n (\n SELECT\n JSONB_AGG(\n JSONB_BUILD_OBJECT(\n 'id', authors.id,\n 'first_name', authors.first_name,\n 'last_name', authors.last_name,\n 'middle_name', authors.middle_name,\n 'annotation_exists', EXISTS(\n SELECT * FROM author_annotations WHERE author = authors.id\n )\n )\n )\n FROM translations\n JOIN authors ON authors.id = translations.author\n WHERE translations.book = b.id\n ) AS \"translators!: Vec\",\n EXISTS(\n SELECT * FROM book_annotations WHERE book = b.id\n ) AS \"annotation_exists!: bool\",\n bs.position\n FROM books b\n JOIN book_sequences bs ON b.id = bs.book\n WHERE\n b.is_deleted = FALSE AND\n bs.sequence = $1 AND\n b.lang = ANY($2)\n ORDER BY bs.position\n LIMIT $3 OFFSET $4\n ", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "id", - "type_info": "Int4" - }, - { - "ordinal": 1, - "name": "title", - "type_info": "Varchar" - }, - { - "ordinal": 2, - "name": "lang", - "type_info": "Varchar" - }, - { - "ordinal": 3, - "name": "file_type", - "type_info": "Varchar" - }, - { - "ordinal": 4, - "name": "year", - "type_info": "Int2" - }, - { - "ordinal": 5, - "name": "available_types!: Vec", - "type_info": "TextArray" - }, - { - "ordinal": 6, - "name": "uploaded", - "type_info": "Date" - }, - { - "ordinal": 7, - "name": "authors!: Vec", - "type_info": "Jsonb" - }, - { - "ordinal": 8, - "name": "translators!: Vec", - "type_info": "Jsonb" - }, - { - "ordinal": 9, - "name": "annotation_exists!: bool", - "type_info": "Bool" - }, - { - "ordinal": 10, - "name": "position", - "type_info": "Int2" - } - ], - "parameters": { - "Left": [ - "Int4", - "TextArray", - "Int8", - "Int8" - ] - }, - "nullable": [ - false, - false, - false, - false, - false, - null, - false, - null, - null, - null, - false - ] - }, - "hash": "0644481879afc3abad9188fde0b00d19638ff16d6c8678d8d4e54a4b6bf5393d" -} diff --git a/.sqlx/query-763625de44f46e1183a1ca2760120ce0303b571ffbc4e5f544340b5134229940.json b/.sqlx/query-1f78b5cbdae5f9732e3637fcfd1605477bafc12a443900276c46df644a7f6d26.json similarity index 55% rename from .sqlx/query-763625de44f46e1183a1ca2760120ce0303b571ffbc4e5f544340b5134229940.json rename to .sqlx/query-1f78b5cbdae5f9732e3637fcfd1605477bafc12a443900276c46df644a7f6d26.json index 76cfb6d..c8cbb46 100644 --- a/.sqlx/query-763625de44f46e1183a1ca2760120ce0303b571ffbc4e5f544340b5134229940.json +++ b/.sqlx/query-1f78b5cbdae5f9732e3637fcfd1605477bafc12a443900276c46df644a7f6d26.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "\n SELECT\n genres.id,\n genres.remote_id,\n genres.code,\n genres.description,\n genres.meta,\n (\n SELECT\n JSONB_BUILD_OBJECT(\n 'id', sources.id,\n 'name', sources.name\n )\n FROM sources\n WHERE sources.id = genres.source\n ) AS \"source!: Source\"\n FROM genres\n ORDER BY genres.id ASC\n ", + "query": "\n SELECT\n genres.id,\n genres.remote_id,\n genres.code,\n genres.description,\n genres.meta,\n (\n SELECT\n ROW(\n sources.id,\n sources.name\n )::source_type\n FROM sources\n WHERE sources.id = genres.source\n ) AS \"source!: Source\"\n FROM genres\n ORDER BY genres.id ASC\n ", "describe": { "columns": [ { @@ -31,7 +31,23 @@ { "ordinal": 5, "name": "source!: Source", - "type_info": "Jsonb" + "type_info": { + "Custom": { + "name": "source_type", + "kind": { + "Composite": [ + [ + "id", + "Int4" + ], + [ + "name", + "Varchar" + ] + ] + } + } + } } ], "parameters": { @@ -46,5 +62,5 @@ null ] }, - "hash": "763625de44f46e1183a1ca2760120ce0303b571ffbc4e5f544340b5134229940" + "hash": "1f78b5cbdae5f9732e3637fcfd1605477bafc12a443900276c46df644a7f6d26" } diff --git a/.sqlx/query-4fcb5676ff01cdeb824340375a2c96bd887d93d7cc6254ce5bead2ff3d7f3971.json b/.sqlx/query-4fcb5676ff01cdeb824340375a2c96bd887d93d7cc6254ce5bead2ff3d7f3971.json new file mode 100644 index 0000000..9ad9b63 --- /dev/null +++ b/.sqlx/query-4fcb5676ff01cdeb824340375a2c96bd887d93d7cc6254ce5bead2ff3d7f3971.json @@ -0,0 +1,210 @@ +{ + "db_name": "PostgreSQL", + "query": "\n SELECT\n b.id,\n b.title,\n b.lang,\n b.file_type,\n b.year,\n CASE WHEN b.file_type = 'fb2' THEN ARRAY['fb2', 'epub', 'mobi', 'fb2zip']::text[] ELSE ARRAY[b.file_type]::text[] END AS \"available_types!: Vec\",\n b.uploaded,\n (\n SELECT\n ARRAY_AGG(\n ROW(\n authors.id,\n authors.first_name,\n authors.last_name,\n authors.middle_name,\n EXISTS(\n SELECT * FROM author_annotations WHERE author = authors.id\n )\n )::author_type\n )\n FROM book_authors\n JOIN authors ON authors.id = book_authors.author\n WHERE book_authors.book = b.id\n ) AS \"authors!: Vec\",\n (\n SELECT\n ARRAY_AGG(\n ROW(\n authors.id,\n authors.first_name,\n authors.last_name,\n authors.middle_name,\n EXISTS(\n SELECT * FROM author_annotations WHERE author = authors.id\n )\n )::author_type\n )\n FROM translations\n JOIN authors ON authors.id = translations.author\n WHERE translations.book = b.id\n ) AS \"translators!: Vec\",\n (\n SELECT\n ARRAY_AGG(\n ROW(\n sequences.id,\n sequences.name\n )::sequence_type\n )\n FROM book_sequences\n JOIN sequences ON sequences.id = book_sequences.sequence\n WHERE book_sequences.book = b.id\n ) AS \"sequences!: Vec\",\n EXISTS(\n SELECT * FROM book_annotations WHERE book = b.id\n ) AS \"annotation_exists!: bool\",\n (\n SELECT\n ROW(\n sources.id,\n sources.name\n )::source_type\n FROM sources\n WHERE sources.id = b.source\n ) AS \"source!: Source\",\n b.remote_id\n FROM books b\n WHERE lang = ANY($1) AND\n ($2::boolean IS NULL OR is_deleted = $2) AND\n ($3::date IS NULL OR uploaded >= $3) AND\n ($4::date IS NULL OR uploaded <= $4) AND\n ($5::integer IS NULL OR id >= $5) AND\n ($6::integer IS NULL OR id <= $6)\n ORDER BY b.id ASC\n OFFSET $7\n LIMIT $8\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id", + "type_info": "Int4" + }, + { + "ordinal": 1, + "name": "title", + "type_info": "Varchar" + }, + { + "ordinal": 2, + "name": "lang", + "type_info": "Varchar" + }, + { + "ordinal": 3, + "name": "file_type", + "type_info": "Varchar" + }, + { + "ordinal": 4, + "name": "year", + "type_info": "Int2" + }, + { + "ordinal": 5, + "name": "available_types!: Vec", + "type_info": "TextArray" + }, + { + "ordinal": 6, + "name": "uploaded", + "type_info": "Date" + }, + { + "ordinal": 7, + "name": "authors!: Vec", + "type_info": { + "Custom": { + "name": "author_type[]", + "kind": { + "Array": { + "Custom": { + "name": "author_type", + "kind": { + "Composite": [ + [ + "id", + "Int4" + ], + [ + "first_name", + "Varchar" + ], + [ + "last_name", + "Varchar" + ], + [ + "middle_name", + "Varchar" + ], + [ + "annotation_exists", + "Bool" + ] + ] + } + } + } + } + } + } + }, + { + "ordinal": 8, + "name": "translators!: Vec", + "type_info": { + "Custom": { + "name": "author_type[]", + "kind": { + "Array": { + "Custom": { + "name": "author_type", + "kind": { + "Composite": [ + [ + "id", + "Int4" + ], + [ + "first_name", + "Varchar" + ], + [ + "last_name", + "Varchar" + ], + [ + "middle_name", + "Varchar" + ], + [ + "annotation_exists", + "Bool" + ] + ] + } + } + } + } + } + } + }, + { + "ordinal": 9, + "name": "sequences!: Vec", + "type_info": { + "Custom": { + "name": "sequence_type[]", + "kind": { + "Array": { + "Custom": { + "name": "sequence_type", + "kind": { + "Composite": [ + [ + "id", + "Int4" + ], + [ + "name", + "Varchar" + ] + ] + } + } + } + } + } + } + }, + { + "ordinal": 10, + "name": "annotation_exists!: bool", + "type_info": "Bool" + }, + { + "ordinal": 11, + "name": "source!: Source", + "type_info": { + "Custom": { + "name": "source_type", + "kind": { + "Composite": [ + [ + "id", + "Int4" + ], + [ + "name", + "Varchar" + ] + ] + } + } + } + }, + { + "ordinal": 12, + "name": "remote_id", + "type_info": "Int4" + } + ], + "parameters": { + "Left": [ + "TextArray", + "Bool", + "Date", + "Date", + "Int4", + "Int4", + "Int8", + "Int8" + ] + }, + "nullable": [ + false, + false, + false, + false, + false, + null, + false, + null, + null, + null, + null, + null, + false + ] + }, + "hash": "4fcb5676ff01cdeb824340375a2c96bd887d93d7cc6254ce5bead2ff3d7f3971" +} diff --git a/.sqlx/query-50379dd90ab755cdbeba57ea4ca62863aa087c35b4afa30c51224fe11cb0a823.json b/.sqlx/query-50379dd90ab755cdbeba57ea4ca62863aa087c35b4afa30c51224fe11cb0a823.json new file mode 100644 index 0000000..52f9df0 --- /dev/null +++ b/.sqlx/query-50379dd90ab755cdbeba57ea4ca62863aa087c35b4afa30c51224fe11cb0a823.json @@ -0,0 +1,132 @@ +{ + "db_name": "PostgreSQL", + "query": "\n SELECT\n b.id,\n b.title,\n b.lang,\n b.file_type,\n b.year,\n CASE WHEN b.file_type = 'fb2' THEN ARRAY['fb2', 'epub', 'mobi', 'fb2zip']::text[] ELSE ARRAY[b.file_type]::text[] END AS \"available_types!: Vec\",\n b.uploaded,\n (\n SELECT\n ARRAY_AGG(\n ROW(\n authors.id,\n authors.first_name,\n authors.last_name,\n authors.middle_name,\n EXISTS(\n SELECT * FROM author_annotations WHERE author = authors.id\n )\n )::author_type\n )\n FROM book_authors\n JOIN authors ON authors.id = book_authors.author\n WHERE book_authors.book = b.id\n ) AS \"authors!: Vec\",\n (\n SELECT\n ARRAY_AGG(\n ROW(\n sequences.id,\n sequences.name\n )::sequence_type\n )\n FROM book_sequences\n JOIN sequences ON sequences.id = book_sequences.sequence\n WHERE book_sequences.book = b.id\n ) AS \"sequences!: Vec\",\n EXISTS(\n SELECT * FROM book_annotations WHERE book = b.id\n ) AS \"annotation_exists!: bool\"\n FROM books b\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id", + "type_info": "Int4" + }, + { + "ordinal": 1, + "name": "title", + "type_info": "Varchar" + }, + { + "ordinal": 2, + "name": "lang", + "type_info": "Varchar" + }, + { + "ordinal": 3, + "name": "file_type", + "type_info": "Varchar" + }, + { + "ordinal": 4, + "name": "year", + "type_info": "Int2" + }, + { + "ordinal": 5, + "name": "available_types!: Vec", + "type_info": "TextArray" + }, + { + "ordinal": 6, + "name": "uploaded", + "type_info": "Date" + }, + { + "ordinal": 7, + "name": "authors!: Vec", + "type_info": { + "Custom": { + "name": "author_type[]", + "kind": { + "Array": { + "Custom": { + "name": "author_type", + "kind": { + "Composite": [ + [ + "id", + "Int4" + ], + [ + "first_name", + "Varchar" + ], + [ + "last_name", + "Varchar" + ], + [ + "middle_name", + "Varchar" + ], + [ + "annotation_exists", + "Bool" + ] + ] + } + } + } + } + } + } + }, + { + "ordinal": 8, + "name": "sequences!: Vec", + "type_info": { + "Custom": { + "name": "sequence_type[]", + "kind": { + "Array": { + "Custom": { + "name": "sequence_type", + "kind": { + "Composite": [ + [ + "id", + "Int4" + ], + [ + "name", + "Varchar" + ] + ] + } + } + } + } + } + } + }, + { + "ordinal": 9, + "name": "annotation_exists!: bool", + "type_info": "Bool" + } + ], + "parameters": { + "Left": [] + }, + "nullable": [ + false, + false, + false, + false, + false, + null, + false, + null, + null, + null + ] + }, + "hash": "50379dd90ab755cdbeba57ea4ca62863aa087c35b4afa30c51224fe11cb0a823" +} diff --git a/.sqlx/query-52cef4b1366f8071f42b772cfe32489050ce4d0b395cb0c93944389b1dfa8251.json b/.sqlx/query-52cef4b1366f8071f42b772cfe32489050ce4d0b395cb0c93944389b1dfa8251.json deleted file mode 100644 index 5465aa5..0000000 --- a/.sqlx/query-52cef4b1366f8071f42b772cfe32489050ce4d0b395cb0c93944389b1dfa8251.json +++ /dev/null @@ -1,112 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "\n SELECT\n b.id,\n b.title,\n b.lang,\n b.file_type,\n b.year,\n CASE WHEN b.file_type = 'fb2' THEN ARRAY['fb2', 'epub', 'mobi', 'fb2zip']::text[] ELSE ARRAY[b.file_type]::text[] END AS \"available_types!: Vec\",\n b.uploaded,\n (\n SELECT\n JSONB_AGG(\n JSONB_BUILD_OBJECT(\n 'id', authors.id,\n 'first_name', authors.first_name,\n 'last_name', authors.last_name,\n 'middle_name', authors.middle_name,\n 'annotation_exists', EXISTS(\n SELECT * FROM author_annotations WHERE author = authors.id\n )\n )\n )\n FROM book_authors\n JOIN authors ON authors.id = book_authors.author\n WHERE book_authors.book = b.id\n ) AS \"authors!: Vec\",\n (\n SELECT\n JSONB_AGG(\n JSONB_BUILD_OBJECT(\n 'id', authors.id,\n 'first_name', authors.first_name,\n 'last_name', authors.last_name,\n 'middle_name', authors.middle_name,\n 'annotation_exists', EXISTS(\n SELECT * FROM author_annotations WHERE author = authors.id\n )\n )\n )\n FROM translations\n JOIN authors ON authors.id = translations.author\n WHERE translations.book = b.id\n ) AS \"translators!: Vec\",\n (\n SELECT\n JSONB_AGG(\n JSONB_BUILD_OBJECT(\n 'id', sequences.id,\n 'name', sequences.name\n )\n )\n FROM book_sequences\n JOIN sequences ON sequences.id = book_sequences.sequence\n WHERE book_sequences.book = b.id\n ) AS \"sequences!: Vec\",\n (\n SELECT\n JSONB_AGG(\n JSONB_BUILD_OBJECT(\n 'id', genres.id,\n 'code', genres.code,\n 'description', genres.description,\n 'meta', genres.meta,\n 'source', JSONB_BUILD_OBJECT(\n 'id', sources.id,\n 'name', sources.name\n )\n )\n )\n FROM book_genres\n JOIN genres ON genres.id = book_genres.genre\n JOIN sources ON sources.id = genres.source\n WHERE book_genres.book = b.id\n ) AS \"genres!: Vec\",\n EXISTS(\n SELECT * FROM book_annotations WHERE book = b.id\n ) AS \"annotation_exists!: bool\",\n (\n SELECT\n JSONB_BUILD_OBJECT(\n 'id', sources.id,\n 'name', sources.name\n )\n FROM sources\n WHERE sources.id = b.source\n ) AS \"source!: Source\",\n b.remote_id,\n b.is_deleted,\n b.pages\n FROM books b\n WHERE b.id = $1\n ", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "id", - "type_info": "Int4" - }, - { - "ordinal": 1, - "name": "title", - "type_info": "Varchar" - }, - { - "ordinal": 2, - "name": "lang", - "type_info": "Varchar" - }, - { - "ordinal": 3, - "name": "file_type", - "type_info": "Varchar" - }, - { - "ordinal": 4, - "name": "year", - "type_info": "Int2" - }, - { - "ordinal": 5, - "name": "available_types!: Vec", - "type_info": "TextArray" - }, - { - "ordinal": 6, - "name": "uploaded", - "type_info": "Date" - }, - { - "ordinal": 7, - "name": "authors!: Vec", - "type_info": "Jsonb" - }, - { - "ordinal": 8, - "name": "translators!: Vec", - "type_info": "Jsonb" - }, - { - "ordinal": 9, - "name": "sequences!: Vec", - "type_info": "Jsonb" - }, - { - "ordinal": 10, - "name": "genres!: Vec", - "type_info": "Jsonb" - }, - { - "ordinal": 11, - "name": "annotation_exists!: bool", - "type_info": "Bool" - }, - { - "ordinal": 12, - "name": "source!: Source", - "type_info": "Jsonb" - }, - { - "ordinal": 13, - "name": "remote_id", - "type_info": "Int4" - }, - { - "ordinal": 14, - "name": "is_deleted", - "type_info": "Bool" - }, - { - "ordinal": 15, - "name": "pages", - "type_info": "Int4" - } - ], - "parameters": { - "Left": [ - "Int4" - ] - }, - "nullable": [ - false, - false, - false, - false, - false, - null, - false, - null, - null, - null, - null, - null, - null, - false, - false, - true - ] - }, - "hash": "52cef4b1366f8071f42b772cfe32489050ce4d0b395cb0c93944389b1dfa8251" -} diff --git a/.sqlx/query-6f91dfb52d18d080bcaf1dfbf7b7d4b6a6168cc33312d767798815d802962ff9.json b/.sqlx/query-6f91dfb52d18d080bcaf1dfbf7b7d4b6a6168cc33312d767798815d802962ff9.json deleted file mode 100644 index 9d9a07a..0000000 --- a/.sqlx/query-6f91dfb52d18d080bcaf1dfbf7b7d4b6a6168cc33312d767798815d802962ff9.json +++ /dev/null @@ -1,74 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "\n SELECT\n b.id,\n b.title,\n b.lang,\n b.file_type,\n b.year,\n CASE WHEN b.file_type = 'fb2' THEN ARRAY['fb2', 'epub', 'mobi', 'fb2zip']::text[] ELSE ARRAY[b.file_type]::text[] END AS \"available_types!: Vec\",\n b.uploaded,\n (\n SELECT\n JSONB_AGG(\n JSONB_BUILD_OBJECT(\n 'id', authors.id,\n 'first_name', authors.first_name,\n 'last_name', authors.last_name,\n 'middle_name', authors.middle_name,\n 'annotation_exists', EXISTS(\n SELECT * FROM author_annotations WHERE author = authors.id\n )\n )\n )\n FROM book_authors\n JOIN authors ON authors.id = book_authors.author\n WHERE book_authors.book = b.id\n ) AS \"authors!: Vec\",\n (\n SELECT\n JSONB_AGG(\n JSONB_BUILD_OBJECT(\n 'id', sequences.id,\n 'name', sequences.name\n )\n )\n FROM book_sequences\n JOIN sequences ON sequences.id = book_sequences.sequence\n WHERE book_sequences.book = b.id\n ) AS \"sequences!: Vec\",\n EXISTS(\n SELECT * FROM book_annotations WHERE book = b.id\n ) AS \"annotation_exists!: bool\"\n FROM books b\n ", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "id", - "type_info": "Int4" - }, - { - "ordinal": 1, - "name": "title", - "type_info": "Varchar" - }, - { - "ordinal": 2, - "name": "lang", - "type_info": "Varchar" - }, - { - "ordinal": 3, - "name": "file_type", - "type_info": "Varchar" - }, - { - "ordinal": 4, - "name": "year", - "type_info": "Int2" - }, - { - "ordinal": 5, - "name": "available_types!: Vec", - "type_info": "TextArray" - }, - { - "ordinal": 6, - "name": "uploaded", - "type_info": "Date" - }, - { - "ordinal": 7, - "name": "authors!: Vec", - "type_info": "Jsonb" - }, - { - "ordinal": 8, - "name": "sequences!: Vec", - "type_info": "Jsonb" - }, - { - "ordinal": 9, - "name": "annotation_exists!: bool", - "type_info": "Bool" - } - ], - "parameters": { - "Left": [] - }, - "nullable": [ - false, - false, - false, - false, - false, - null, - false, - null, - null, - null - ] - }, - "hash": "6f91dfb52d18d080bcaf1dfbf7b7d4b6a6168cc33312d767798815d802962ff9" -} diff --git a/.sqlx/query-71a1b03481c1642c963b1641da8dbcc308fee8ca82b5800746f1568fb358bc37.json b/.sqlx/query-71a1b03481c1642c963b1641da8dbcc308fee8ca82b5800746f1568fb358bc37.json new file mode 100644 index 0000000..591a9b1 --- /dev/null +++ b/.sqlx/query-71a1b03481c1642c963b1641da8dbcc308fee8ca82b5800746f1568fb358bc37.json @@ -0,0 +1,277 @@ +{ + "db_name": "PostgreSQL", + "query": "\n SELECT\n b.id,\n b.title,\n b.lang,\n b.file_type,\n b.year,\n CASE WHEN b.file_type = 'fb2' THEN ARRAY['fb2', 'epub', 'mobi', 'fb2zip']::text[] ELSE ARRAY[b.file_type]::text[] END AS \"available_types!: Vec\",\n b.uploaded,\n (\n SELECT\n ARRAY_AGG(\n ROW(\n authors.id,\n authors.first_name,\n authors.last_name,\n authors.middle_name,\n EXISTS(\n SELECT * FROM author_annotations WHERE author = authors.id\n )\n )::author_type\n )\n FROM book_authors\n JOIN authors ON authors.id = book_authors.author\n WHERE book_authors.book = b.id\n ) AS \"authors!: Vec\",\n (\n SELECT\n ARRAY_AGG(\n ROW(\n authors.id,\n authors.first_name,\n authors.last_name,\n authors.middle_name,\n EXISTS(\n SELECT * FROM author_annotations WHERE author = authors.id\n )\n )::author_type\n )\n FROM translations\n JOIN authors ON authors.id = translations.author\n WHERE translations.book = b.id\n ) AS \"translators!: Vec\",\n (\n SELECT\n ARRAY_AGG(\n ROW(\n sequences.id,\n sequences.name\n )::sequence_type\n )\n FROM book_sequences\n JOIN sequences ON sequences.id = book_sequences.sequence\n WHERE book_sequences.book = b.id\n ) AS \"sequences!: Vec\",\n (\n SELECT\n ARRAY_AGG(\n ROW(\n genres.id,\n ROW(\n sources.id,\n sources.name\n )::source_type,\n remote_id,\n genres.code,\n genres.description,\n genres.meta\n )::genre_type\n )\n FROM book_genres\n JOIN genres ON genres.id = book_genres.genre\n JOIN sources ON sources.id = genres.source\n WHERE book_genres.book = b.id\n ) AS \"genres!: Vec\",\n EXISTS(\n SELECT * FROM book_annotations WHERE book = b.id\n ) AS \"annotation_exists!: bool\",\n (\n SELECT\n ROW(\n sources.id,\n sources.name\n )::source_type\n FROM sources\n WHERE sources.id = b.source\n ) AS \"source!: Source\",\n b.remote_id,\n b.is_deleted,\n b.pages\n FROM books b\n WHERE b.source = $1 AND b.remote_id = $2\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id", + "type_info": "Int4" + }, + { + "ordinal": 1, + "name": "title", + "type_info": "Varchar" + }, + { + "ordinal": 2, + "name": "lang", + "type_info": "Varchar" + }, + { + "ordinal": 3, + "name": "file_type", + "type_info": "Varchar" + }, + { + "ordinal": 4, + "name": "year", + "type_info": "Int2" + }, + { + "ordinal": 5, + "name": "available_types!: Vec", + "type_info": "TextArray" + }, + { + "ordinal": 6, + "name": "uploaded", + "type_info": "Date" + }, + { + "ordinal": 7, + "name": "authors!: Vec", + "type_info": { + "Custom": { + "name": "author_type[]", + "kind": { + "Array": { + "Custom": { + "name": "author_type", + "kind": { + "Composite": [ + [ + "id", + "Int4" + ], + [ + "first_name", + "Varchar" + ], + [ + "last_name", + "Varchar" + ], + [ + "middle_name", + "Varchar" + ], + [ + "annotation_exists", + "Bool" + ] + ] + } + } + } + } + } + } + }, + { + "ordinal": 8, + "name": "translators!: Vec", + "type_info": { + "Custom": { + "name": "author_type[]", + "kind": { + "Array": { + "Custom": { + "name": "author_type", + "kind": { + "Composite": [ + [ + "id", + "Int4" + ], + [ + "first_name", + "Varchar" + ], + [ + "last_name", + "Varchar" + ], + [ + "middle_name", + "Varchar" + ], + [ + "annotation_exists", + "Bool" + ] + ] + } + } + } + } + } + } + }, + { + "ordinal": 9, + "name": "sequences!: Vec", + "type_info": { + "Custom": { + "name": "sequence_type[]", + "kind": { + "Array": { + "Custom": { + "name": "sequence_type", + "kind": { + "Composite": [ + [ + "id", + "Int4" + ], + [ + "name", + "Varchar" + ] + ] + } + } + } + } + } + } + }, + { + "ordinal": 10, + "name": "genres!: Vec", + "type_info": { + "Custom": { + "name": "genre_type[]", + "kind": { + "Array": { + "Custom": { + "name": "genre_type", + "kind": { + "Composite": [ + [ + "id", + "Int4" + ], + [ + "source", + { + "Custom": { + "name": "source_type", + "kind": { + "Composite": [ + [ + "id", + "Int4" + ], + [ + "name", + "Varchar" + ] + ] + } + } + } + ], + [ + "remote_id", + "Int4" + ], + [ + "code", + "Varchar" + ], + [ + "description", + "Varchar" + ], + [ + "meta", + "Varchar" + ] + ] + } + } + } + } + } + } + }, + { + "ordinal": 11, + "name": "annotation_exists!: bool", + "type_info": "Bool" + }, + { + "ordinal": 12, + "name": "source!: Source", + "type_info": { + "Custom": { + "name": "source_type", + "kind": { + "Composite": [ + [ + "id", + "Int4" + ], + [ + "name", + "Varchar" + ] + ] + } + } + } + }, + { + "ordinal": 13, + "name": "remote_id", + "type_info": "Int4" + }, + { + "ordinal": 14, + "name": "is_deleted", + "type_info": "Bool" + }, + { + "ordinal": 15, + "name": "pages", + "type_info": "Int4" + } + ], + "parameters": { + "Left": [ + "Int2", + "Int4" + ] + }, + "nullable": [ + false, + false, + false, + false, + false, + null, + false, + null, + null, + null, + null, + null, + null, + false, + false, + true + ] + }, + "hash": "71a1b03481c1642c963b1641da8dbcc308fee8ca82b5800746f1568fb358bc37" +} diff --git a/.sqlx/query-8050a82de1de70e6ca60a02227795a263774da36fb00b97b00ed4ecd9a7ec778.json b/.sqlx/query-8050a82de1de70e6ca60a02227795a263774da36fb00b97b00ed4ecd9a7ec778.json deleted file mode 100644 index 5351a64..0000000 --- a/.sqlx/query-8050a82de1de70e6ca60a02227795a263774da36fb00b97b00ed4ecd9a7ec778.json +++ /dev/null @@ -1,101 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "\n SELECT\n b.id,\n b.title,\n b.lang,\n b.file_type,\n b.year,\n CASE WHEN b.file_type = 'fb2' THEN ARRAY['fb2', 'epub', 'mobi', 'fb2zip']::text[] ELSE ARRAY[b.file_type]::text[] END AS \"available_types!: Vec\",\n b.uploaded,\n (\n SELECT\n JSONB_AGG(\n JSONB_BUILD_OBJECT(\n 'id', authors.id,\n 'first_name', authors.first_name,\n 'last_name', authors.last_name,\n 'middle_name', authors.middle_name,\n 'annotation_exists', EXISTS(\n SELECT * FROM author_annotations WHERE author = authors.id\n )\n )\n )\n FROM book_authors\n JOIN authors ON authors.id = book_authors.author\n WHERE book_authors.book = b.id\n ) AS \"authors!: Vec\",\n (\n SELECT\n JSONB_AGG(\n JSONB_BUILD_OBJECT(\n 'id', authors.id,\n 'first_name', authors.first_name,\n 'last_name', authors.last_name,\n 'middle_name', authors.middle_name,\n 'annotation_exists', EXISTS(\n SELECT * FROM author_annotations WHERE author = authors.id\n )\n )\n )\n FROM translations\n JOIN authors ON authors.id = translations.author\n WHERE translations.book = b.id\n ) AS \"translators!: Vec\",\n (\n SELECT\n JSONB_AGG(\n JSONB_BUILD_OBJECT(\n 'id', sequences.id,\n 'name', sequences.name\n )\n )\n FROM book_sequences\n JOIN sequences ON sequences.id = book_sequences.sequence\n WHERE book_sequences.book = b.id\n ) AS \"sequences!: Vec\",\n EXISTS(\n SELECT * FROM book_annotations WHERE book = b.id\n ) AS \"annotation_exists!: bool\",\n (\n SELECT\n JSONB_BUILD_OBJECT(\n 'id', sources.id,\n 'name', sources.name\n )\n FROM sources\n WHERE sources.id = b.source\n ) AS \"source!: Source\",\n b.remote_id\n FROM books b\n WHERE lang = ANY($1) AND\n ($2::boolean IS NULL OR is_deleted = $2) AND\n ($3::date IS NULL OR uploaded >= $3) AND\n ($4::date IS NULL OR uploaded <= $4) AND\n ($5::integer IS NULL OR id >= $5) AND\n ($6::integer IS NULL OR id <= $6)\n ORDER BY b.id ASC\n OFFSET $7\n LIMIT $8\n ", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "id", - "type_info": "Int4" - }, - { - "ordinal": 1, - "name": "title", - "type_info": "Varchar" - }, - { - "ordinal": 2, - "name": "lang", - "type_info": "Varchar" - }, - { - "ordinal": 3, - "name": "file_type", - "type_info": "Varchar" - }, - { - "ordinal": 4, - "name": "year", - "type_info": "Int2" - }, - { - "ordinal": 5, - "name": "available_types!: Vec", - "type_info": "TextArray" - }, - { - "ordinal": 6, - "name": "uploaded", - "type_info": "Date" - }, - { - "ordinal": 7, - "name": "authors!: Vec", - "type_info": "Jsonb" - }, - { - "ordinal": 8, - "name": "translators!: Vec", - "type_info": "Jsonb" - }, - { - "ordinal": 9, - "name": "sequences!: Vec", - "type_info": "Jsonb" - }, - { - "ordinal": 10, - "name": "annotation_exists!: bool", - "type_info": "Bool" - }, - { - "ordinal": 11, - "name": "source!: Source", - "type_info": "Jsonb" - }, - { - "ordinal": 12, - "name": "remote_id", - "type_info": "Int4" - } - ], - "parameters": { - "Left": [ - "TextArray", - "Bool", - "Date", - "Date", - "Int4", - "Int4", - "Int8", - "Int8" - ] - }, - "nullable": [ - false, - false, - false, - false, - false, - null, - false, - null, - null, - null, - null, - null, - false - ] - }, - "hash": "8050a82de1de70e6ca60a02227795a263774da36fb00b97b00ed4ecd9a7ec778" -} diff --git a/.sqlx/query-91845687097ff0ce0f2f1dd51d2b61d2abf1cd2f04c2b3371f32720501c5f790.json b/.sqlx/query-91845687097ff0ce0f2f1dd51d2b61d2abf1cd2f04c2b3371f32720501c5f790.json deleted file mode 100644 index 1bd18c2..0000000 --- a/.sqlx/query-91845687097ff0ce0f2f1dd51d2b61d2abf1cd2f04c2b3371f32720501c5f790.json +++ /dev/null @@ -1,79 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "\n SELECT\n b.id,\n b.title,\n b.lang,\n b.file_type,\n b.year,\n CASE WHEN b.file_type = 'fb2' THEN ARRAY['fb2', 'epub', 'mobi', 'fb2zip']::text[] ELSE ARRAY[b.file_type]::text[] END AS \"available_types!: Vec\",\n b.uploaded,\n (\n SELECT\n JSONB_AGG(\n JSONB_BUILD_OBJECT(\n 'id', authors.id,\n 'first_name', authors.first_name,\n 'last_name', authors.last_name,\n 'middle_name', authors.middle_name,\n 'annotation_exists', EXISTS(\n SELECT * FROM author_annotations WHERE author = authors.id\n )\n )\n )\n FROM translations\n JOIN authors ON authors.id = translations.author\n WHERE translations.book = b.id\n ) AS \"translators!: Vec\",\n (\n SELECT\n JSONB_AGG(\n JSONB_BUILD_OBJECT(\n 'id', sequences.id,\n 'name', sequences.name\n )\n )\n FROM book_sequences\n JOIN sequences ON sequences.id = book_sequences.sequence\n WHERE book_sequences.book = b.id\n ) AS \"sequences!: Vec\",\n EXISTS(\n SELECT * FROM book_annotations WHERE book = b.id\n ) AS \"annotation_exists!: bool\"\n FROM books b\n JOIN book_authors ba ON b.id = ba.book\n WHERE b.is_deleted = false AND ba.author = $1 AND b.lang = ANY($2)\n ORDER BY b.title ASC\n OFFSET $3\n LIMIT $4\n ", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "id", - "type_info": "Int4" - }, - { - "ordinal": 1, - "name": "title", - "type_info": "Varchar" - }, - { - "ordinal": 2, - "name": "lang", - "type_info": "Varchar" - }, - { - "ordinal": 3, - "name": "file_type", - "type_info": "Varchar" - }, - { - "ordinal": 4, - "name": "year", - "type_info": "Int2" - }, - { - "ordinal": 5, - "name": "available_types!: Vec", - "type_info": "TextArray" - }, - { - "ordinal": 6, - "name": "uploaded", - "type_info": "Date" - }, - { - "ordinal": 7, - "name": "translators!: Vec", - "type_info": "Jsonb" - }, - { - "ordinal": 8, - "name": "sequences!: Vec", - "type_info": "Jsonb" - }, - { - "ordinal": 9, - "name": "annotation_exists!: bool", - "type_info": "Bool" - } - ], - "parameters": { - "Left": [ - "Int4", - "TextArray", - "Int8", - "Int8" - ] - }, - "nullable": [ - false, - false, - false, - false, - false, - null, - false, - null, - null, - null - ] - }, - "hash": "91845687097ff0ce0f2f1dd51d2b61d2abf1cd2f04c2b3371f32720501c5f790" -} diff --git a/.sqlx/query-868081a73c2ee8e44db3d19d82afed39949d5310dfccdea2bbda1086f8ff9120.json b/.sqlx/query-a22bfa2e92bf4a3b0710388c6c5bbfa50f24864b183bb304d35cea18babd8ce3.json similarity index 54% rename from .sqlx/query-868081a73c2ee8e44db3d19d82afed39949d5310dfccdea2bbda1086f8ff9120.json rename to .sqlx/query-a22bfa2e92bf4a3b0710388c6c5bbfa50f24864b183bb304d35cea18babd8ce3.json index feec415..36fd97b 100644 --- a/.sqlx/query-868081a73c2ee8e44db3d19d82afed39949d5310dfccdea2bbda1086f8ff9120.json +++ b/.sqlx/query-a22bfa2e92bf4a3b0710388c6c5bbfa50f24864b183bb304d35cea18babd8ce3.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "\n SELECT\n genres.id,\n genres.remote_id,\n genres.code,\n genres.description,\n genres.meta,\n (\n SELECT\n JSONB_BUILD_OBJECT(\n 'id', sources.id,\n 'name', sources.name\n )\n FROM sources\n WHERE sources.id = genres.source\n ) AS \"source!: Source\"\n FROM genres\n WHERE (meta = $1 OR $1 IS NULL)\n ORDER BY genres.id ASC\n LIMIT $2 OFFSET $3\n ", + "query": "\n SELECT\n genres.id,\n genres.remote_id,\n genres.code,\n genres.description,\n genres.meta,\n (\n SELECT\n ROW(\n sources.id,\n sources.name\n )::source_type\n FROM sources\n WHERE sources.id = genres.source\n ) AS \"source!: Source\"\n FROM genres\n WHERE (meta = $1 OR $1 IS NULL)\n ORDER BY genres.id ASC\n LIMIT $2 OFFSET $3\n ", "describe": { "columns": [ { @@ -31,7 +31,23 @@ { "ordinal": 5, "name": "source!: Source", - "type_info": "Jsonb" + "type_info": { + "Custom": { + "name": "source_type", + "kind": { + "Composite": [ + [ + "id", + "Int4" + ], + [ + "name", + "Varchar" + ] + ] + } + } + } } ], "parameters": { @@ -50,5 +66,5 @@ null ] }, - "hash": "868081a73c2ee8e44db3d19d82afed39949d5310dfccdea2bbda1086f8ff9120" + "hash": "a22bfa2e92bf4a3b0710388c6c5bbfa50f24864b183bb304d35cea18babd8ce3" } diff --git a/.sqlx/query-bc0b43e31b7a519ca33aaf431958dbefffbb9ee0acfb8de275eaec3ced2e38ed.json b/.sqlx/query-bc0b43e31b7a519ca33aaf431958dbefffbb9ee0acfb8de275eaec3ced2e38ed.json new file mode 100644 index 0000000..151a251 --- /dev/null +++ b/.sqlx/query-bc0b43e31b7a519ca33aaf431958dbefffbb9ee0acfb8de275eaec3ced2e38ed.json @@ -0,0 +1,137 @@ +{ + "db_name": "PostgreSQL", + "query": "\n SELECT\n b.id,\n b.title,\n b.lang,\n b.file_type,\n b.year,\n CASE WHEN b.file_type = 'fb2' THEN ARRAY['fb2', 'epub', 'mobi', 'fb2zip']::text[] ELSE ARRAY[b.file_type]::text[] END AS \"available_types!: Vec\",\n b.uploaded,\n (\n SELECT\n ARRAY_AGG(\n ROW(\n authors.id,\n authors.first_name,\n authors.last_name,\n authors.middle_name,\n EXISTS(\n SELECT * FROM author_annotations WHERE author = authors.id\n )\n )::author_type\n )\n FROM translations\n JOIN authors ON authors.id = translations.author\n WHERE translations.book = b.id\n ) AS \"translators!: Vec\",\n (\n SELECT\n ARRAY_AGG(\n ROW(\n sequences.id,\n sequences.name\n )::sequence_type\n )\n FROM book_sequences\n JOIN sequences ON sequences.id = book_sequences.sequence\n WHERE book_sequences.book = b.id\n ) AS \"sequences!: Vec\",\n EXISTS(\n SELECT * FROM book_annotations WHERE book = b.id\n ) AS \"annotation_exists!: bool\"\n FROM books b\n JOIN book_authors ba ON b.id = ba.book\n WHERE b.is_deleted = false AND ba.author = $1 AND b.lang = ANY($2)\n ORDER BY b.title ASC\n OFFSET $3\n LIMIT $4\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id", + "type_info": "Int4" + }, + { + "ordinal": 1, + "name": "title", + "type_info": "Varchar" + }, + { + "ordinal": 2, + "name": "lang", + "type_info": "Varchar" + }, + { + "ordinal": 3, + "name": "file_type", + "type_info": "Varchar" + }, + { + "ordinal": 4, + "name": "year", + "type_info": "Int2" + }, + { + "ordinal": 5, + "name": "available_types!: Vec", + "type_info": "TextArray" + }, + { + "ordinal": 6, + "name": "uploaded", + "type_info": "Date" + }, + { + "ordinal": 7, + "name": "translators!: Vec", + "type_info": { + "Custom": { + "name": "author_type[]", + "kind": { + "Array": { + "Custom": { + "name": "author_type", + "kind": { + "Composite": [ + [ + "id", + "Int4" + ], + [ + "first_name", + "Varchar" + ], + [ + "last_name", + "Varchar" + ], + [ + "middle_name", + "Varchar" + ], + [ + "annotation_exists", + "Bool" + ] + ] + } + } + } + } + } + } + }, + { + "ordinal": 8, + "name": "sequences!: Vec", + "type_info": { + "Custom": { + "name": "sequence_type[]", + "kind": { + "Array": { + "Custom": { + "name": "sequence_type", + "kind": { + "Composite": [ + [ + "id", + "Int4" + ], + [ + "name", + "Varchar" + ] + ] + } + } + } + } + } + } + }, + { + "ordinal": 9, + "name": "annotation_exists!: bool", + "type_info": "Bool" + } + ], + "parameters": { + "Left": [ + "Int4", + "TextArray", + "Int8", + "Int8" + ] + }, + "nullable": [ + false, + false, + false, + false, + false, + null, + false, + null, + null, + null + ] + }, + "hash": "bc0b43e31b7a519ca33aaf431958dbefffbb9ee0acfb8de275eaec3ced2e38ed" +} diff --git a/.sqlx/query-c270823ac20835ebeba0fca557c8bb237bf9f4fa7c5b1956e2cf491b01ae30b0.json b/.sqlx/query-c270823ac20835ebeba0fca557c8bb237bf9f4fa7c5b1956e2cf491b01ae30b0.json deleted file mode 100644 index 7afb30a..0000000 --- a/.sqlx/query-c270823ac20835ebeba0fca557c8bb237bf9f4fa7c5b1956e2cf491b01ae30b0.json +++ /dev/null @@ -1,82 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "\n SELECT\n b.id,\n b.title,\n b.lang,\n b.file_type,\n b.year,\n CASE WHEN b.file_type = 'fb2' THEN ARRAY['fb2', 'epub', 'mobi', 'fb2zip']::text[] ELSE ARRAY[b.file_type]::text[] END AS \"available_types!: Vec\",\n b.uploaded,\n (\n SELECT\n JSONB_AGG(\n JSONB_BUILD_OBJECT(\n 'id', authors.id,\n 'first_name', authors.first_name,\n 'last_name', authors.last_name,\n 'middle_name', authors.middle_name,\n 'annotation_exists', EXISTS(\n SELECT * FROM author_annotations WHERE author = authors.id\n )\n )\n )\n FROM book_authors\n JOIN authors ON authors.id = book_authors.author\n WHERE book_authors.book = b.id\n ) AS \"authors!: Vec\",\n (\n SELECT\n JSONB_AGG(\n JSONB_BUILD_OBJECT(\n 'id', authors.id,\n 'first_name', authors.first_name,\n 'last_name', authors.last_name,\n 'middle_name', authors.middle_name,\n 'annotation_exists', EXISTS(\n SELECT * FROM author_annotations WHERE author = authors.id\n )\n )\n )\n FROM translations\n JOIN authors ON authors.id = translations.author\n WHERE translations.book = b.id\n ) AS \"translators!: Vec\",\n (\n SELECT\n JSONB_AGG(\n JSONB_BUILD_OBJECT(\n 'id', sequences.id,\n 'name', sequences.name\n )\n )\n FROM book_sequences\n JOIN sequences ON sequences.id = book_sequences.sequence\n WHERE book_sequences.book = b.id\n ) AS \"sequences!: Vec\",\n EXISTS(\n SELECT * FROM book_annotations WHERE book = b.id\n ) AS \"annotation_exists!: bool\"\n FROM books b\n WHERE b.id = ANY($1)\n ", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "id", - "type_info": "Int4" - }, - { - "ordinal": 1, - "name": "title", - "type_info": "Varchar" - }, - { - "ordinal": 2, - "name": "lang", - "type_info": "Varchar" - }, - { - "ordinal": 3, - "name": "file_type", - "type_info": "Varchar" - }, - { - "ordinal": 4, - "name": "year", - "type_info": "Int2" - }, - { - "ordinal": 5, - "name": "available_types!: Vec", - "type_info": "TextArray" - }, - { - "ordinal": 6, - "name": "uploaded", - "type_info": "Date" - }, - { - "ordinal": 7, - "name": "authors!: Vec", - "type_info": "Jsonb" - }, - { - "ordinal": 8, - "name": "translators!: Vec", - "type_info": "Jsonb" - }, - { - "ordinal": 9, - "name": "sequences!: Vec", - "type_info": "Jsonb" - }, - { - "ordinal": 10, - "name": "annotation_exists!: bool", - "type_info": "Bool" - } - ], - "parameters": { - "Left": [ - "Int4Array" - ] - }, - "nullable": [ - false, - false, - false, - false, - false, - null, - false, - null, - null, - null, - null - ] - }, - "hash": "c270823ac20835ebeba0fca557c8bb237bf9f4fa7c5b1956e2cf491b01ae30b0" -} diff --git a/.sqlx/query-dde0ea9311fc1e4b0e300b9c9051282e1899b0d9c15567c9a15d0e39484cbb37.json b/.sqlx/query-dde0ea9311fc1e4b0e300b9c9051282e1899b0d9c15567c9a15d0e39484cbb37.json new file mode 100644 index 0000000..cf9afa4 --- /dev/null +++ b/.sqlx/query-dde0ea9311fc1e4b0e300b9c9051282e1899b0d9c15567c9a15d0e39484cbb37.json @@ -0,0 +1,155 @@ +{ + "db_name": "PostgreSQL", + "query": "\n SELECT\n b.id,\n b.title,\n b.lang,\n b.file_type,\n b.year,\n CASE WHEN b.file_type = 'fb2' THEN ARRAY['fb2', 'epub', 'mobi', 'fb2zip']::text[] ELSE ARRAY[b.file_type]::text[] END AS \"available_types!: Vec\",\n b.uploaded,\n (\n SELECT\n ARRAY_AGG(\n ROW(\n authors.id,\n authors.first_name,\n authors.last_name,\n authors.middle_name,\n EXISTS(\n SELECT * FROM author_annotations WHERE author = authors.id\n )\n )::author_type\n )\n FROM book_authors\n JOIN authors ON authors.id = book_authors.author\n WHERE book_authors.book = b.id\n ) AS \"authors!: Vec\",\n (\n SELECT\n ARRAY_AGG(\n ROW(\n authors.id,\n authors.first_name,\n authors.last_name,\n authors.middle_name,\n EXISTS(\n SELECT * FROM author_annotations WHERE author = authors.id\n )\n )::author_type\n )\n FROM translations\n JOIN authors ON authors.id = translations.author\n WHERE translations.book = b.id\n ) AS \"translators!: Vec\",\n EXISTS(\n SELECT * FROM book_annotations WHERE book = b.id\n ) AS \"annotation_exists!: bool\",\n bs.position\n FROM books b\n JOIN book_sequences bs ON b.id = bs.book\n WHERE\n b.is_deleted = FALSE AND\n bs.sequence = $1 AND\n b.lang = ANY($2)\n ORDER BY bs.position\n LIMIT $3 OFFSET $4\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id", + "type_info": "Int4" + }, + { + "ordinal": 1, + "name": "title", + "type_info": "Varchar" + }, + { + "ordinal": 2, + "name": "lang", + "type_info": "Varchar" + }, + { + "ordinal": 3, + "name": "file_type", + "type_info": "Varchar" + }, + { + "ordinal": 4, + "name": "year", + "type_info": "Int2" + }, + { + "ordinal": 5, + "name": "available_types!: Vec", + "type_info": "TextArray" + }, + { + "ordinal": 6, + "name": "uploaded", + "type_info": "Date" + }, + { + "ordinal": 7, + "name": "authors!: Vec", + "type_info": { + "Custom": { + "name": "author_type[]", + "kind": { + "Array": { + "Custom": { + "name": "author_type", + "kind": { + "Composite": [ + [ + "id", + "Int4" + ], + [ + "first_name", + "Varchar" + ], + [ + "last_name", + "Varchar" + ], + [ + "middle_name", + "Varchar" + ], + [ + "annotation_exists", + "Bool" + ] + ] + } + } + } + } + } + } + }, + { + "ordinal": 8, + "name": "translators!: Vec", + "type_info": { + "Custom": { + "name": "author_type[]", + "kind": { + "Array": { + "Custom": { + "name": "author_type", + "kind": { + "Composite": [ + [ + "id", + "Int4" + ], + [ + "first_name", + "Varchar" + ], + [ + "last_name", + "Varchar" + ], + [ + "middle_name", + "Varchar" + ], + [ + "annotation_exists", + "Bool" + ] + ] + } + } + } + } + } + } + }, + { + "ordinal": 9, + "name": "annotation_exists!: bool", + "type_info": "Bool" + }, + { + "ordinal": 10, + "name": "position", + "type_info": "Int2" + } + ], + "parameters": { + "Left": [ + "Int4", + "TextArray", + "Int8", + "Int8" + ] + }, + "nullable": [ + false, + false, + false, + false, + false, + null, + false, + null, + null, + null, + false + ] + }, + "hash": "dde0ea9311fc1e4b0e300b9c9051282e1899b0d9c15567c9a15d0e39484cbb37" +} diff --git a/.sqlx/query-df1babb391f678c6c4e79a382f43b248c47c57a78620a7147b1f42a886154d8d.json b/.sqlx/query-df1babb391f678c6c4e79a382f43b248c47c57a78620a7147b1f42a886154d8d.json new file mode 100644 index 0000000..97ec971 --- /dev/null +++ b/.sqlx/query-df1babb391f678c6c4e79a382f43b248c47c57a78620a7147b1f42a886154d8d.json @@ -0,0 +1,175 @@ +{ + "db_name": "PostgreSQL", + "query": "\n SELECT\n b.id,\n b.title,\n b.lang,\n b.file_type,\n b.year,\n CASE WHEN b.file_type = 'fb2' THEN ARRAY['fb2', 'epub', 'mobi', 'fb2zip']::text[] ELSE ARRAY[b.file_type]::text[] END AS \"available_types!: Vec\",\n b.uploaded,\n (\n SELECT\n ARRAY_AGG(\n ROW(\n authors.id,\n authors.first_name,\n authors.last_name,\n authors.middle_name,\n EXISTS(\n SELECT * FROM author_annotations WHERE author = authors.id\n )\n )::author_type\n )\n FROM book_authors\n JOIN authors ON authors.id = book_authors.author\n WHERE book_authors.book = b.id\n ) AS \"authors!: Vec\",\n (\n SELECT\n ARRAY_AGG(\n ROW(\n authors.id,\n authors.first_name,\n authors.last_name,\n authors.middle_name,\n EXISTS(\n SELECT * FROM author_annotations WHERE author = authors.id\n )\n )::author_type\n )\n FROM translations\n JOIN authors ON authors.id = translations.author\n WHERE translations.book = b.id\n ) AS \"translators!: Vec\",\n (\n SELECT\n ARRAY_AGG(\n ROW(\n sequences.id,\n sequences.name\n )::sequence_type\n )\n FROM book_sequences\n JOIN sequences ON sequences.id = book_sequences.sequence\n WHERE book_sequences.book = b.id\n ) AS \"sequences!: Vec\",\n EXISTS(\n SELECT * FROM book_annotations WHERE book = b.id\n ) AS \"annotation_exists!: bool\"\n FROM books b\n WHERE b.id = ANY($1)\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id", + "type_info": "Int4" + }, + { + "ordinal": 1, + "name": "title", + "type_info": "Varchar" + }, + { + "ordinal": 2, + "name": "lang", + "type_info": "Varchar" + }, + { + "ordinal": 3, + "name": "file_type", + "type_info": "Varchar" + }, + { + "ordinal": 4, + "name": "year", + "type_info": "Int2" + }, + { + "ordinal": 5, + "name": "available_types!: Vec", + "type_info": "TextArray" + }, + { + "ordinal": 6, + "name": "uploaded", + "type_info": "Date" + }, + { + "ordinal": 7, + "name": "authors!: Vec", + "type_info": { + "Custom": { + "name": "author_type[]", + "kind": { + "Array": { + "Custom": { + "name": "author_type", + "kind": { + "Composite": [ + [ + "id", + "Int4" + ], + [ + "first_name", + "Varchar" + ], + [ + "last_name", + "Varchar" + ], + [ + "middle_name", + "Varchar" + ], + [ + "annotation_exists", + "Bool" + ] + ] + } + } + } + } + } + } + }, + { + "ordinal": 8, + "name": "translators!: Vec", + "type_info": { + "Custom": { + "name": "author_type[]", + "kind": { + "Array": { + "Custom": { + "name": "author_type", + "kind": { + "Composite": [ + [ + "id", + "Int4" + ], + [ + "first_name", + "Varchar" + ], + [ + "last_name", + "Varchar" + ], + [ + "middle_name", + "Varchar" + ], + [ + "annotation_exists", + "Bool" + ] + ] + } + } + } + } + } + } + }, + { + "ordinal": 9, + "name": "sequences!: Vec", + "type_info": { + "Custom": { + "name": "sequence_type[]", + "kind": { + "Array": { + "Custom": { + "name": "sequence_type", + "kind": { + "Composite": [ + [ + "id", + "Int4" + ], + [ + "name", + "Varchar" + ] + ] + } + } + } + } + } + } + }, + { + "ordinal": 10, + "name": "annotation_exists!: bool", + "type_info": "Bool" + } + ], + "parameters": { + "Left": [ + "Int4Array" + ] + }, + "nullable": [ + false, + false, + false, + false, + false, + null, + false, + null, + null, + null, + null + ] + }, + "hash": "df1babb391f678c6c4e79a382f43b248c47c57a78620a7147b1f42a886154d8d" +} diff --git a/.sqlx/query-e6cf55988b86d72c594915c9e5a015d71106794415fb267d6f71d512e9831012.json b/.sqlx/query-e6cf55988b86d72c594915c9e5a015d71106794415fb267d6f71d512e9831012.json deleted file mode 100644 index 7d03754..0000000 --- a/.sqlx/query-e6cf55988b86d72c594915c9e5a015d71106794415fb267d6f71d512e9831012.json +++ /dev/null @@ -1,113 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "\n SELECT\n b.id,\n b.title,\n b.lang,\n b.file_type,\n b.year,\n CASE WHEN b.file_type = 'fb2' THEN ARRAY['fb2', 'epub', 'mobi', 'fb2zip']::text[] ELSE ARRAY[b.file_type]::text[] END AS \"available_types!: Vec\",\n b.uploaded,\n (\n SELECT\n JSONB_AGG(\n JSONB_BUILD_OBJECT(\n 'id', authors.id,\n 'first_name', authors.first_name,\n 'last_name', authors.last_name,\n 'middle_name', authors.middle_name,\n 'annotation_exists', EXISTS(\n SELECT * FROM author_annotations WHERE author = authors.id\n )\n )\n )\n FROM book_authors\n JOIN authors ON authors.id = book_authors.author\n WHERE book_authors.book = b.id\n ) AS \"authors!: Vec\",\n (\n SELECT\n JSONB_AGG(\n JSONB_BUILD_OBJECT(\n 'id', authors.id,\n 'first_name', authors.first_name,\n 'last_name', authors.last_name,\n 'middle_name', authors.middle_name,\n 'annotation_exists', EXISTS(\n SELECT * FROM author_annotations WHERE author = authors.id\n )\n )\n )\n FROM translations\n JOIN authors ON authors.id = translations.author\n WHERE translations.book = b.id\n ) AS \"translators!: Vec\",\n (\n SELECT\n JSONB_AGG(\n JSONB_BUILD_OBJECT(\n 'id', sequences.id,\n 'name', sequences.name\n )\n )\n FROM book_sequences\n JOIN sequences ON sequences.id = book_sequences.sequence\n WHERE book_sequences.book = b.id\n ) AS \"sequences!: Vec\",\n (\n SELECT\n JSONB_AGG(\n JSONB_BUILD_OBJECT(\n 'id', genres.id,\n 'code', genres.code,\n 'description', genres.description,\n 'meta', genres.meta,\n 'source', JSONB_BUILD_OBJECT(\n 'id', sources.id,\n 'name', sources.name\n )\n )\n )\n FROM book_genres\n JOIN genres ON genres.id = book_genres.genre\n JOIN sources ON sources.id = genres.source\n WHERE book_genres.book = b.id\n ) AS \"genres!: Vec\",\n EXISTS(\n SELECT * FROM book_annotations WHERE book = b.id\n ) AS \"annotation_exists!: bool\",\n (\n SELECT\n JSONB_BUILD_OBJECT(\n 'id', sources.id,\n 'name', sources.name\n )\n FROM sources\n WHERE sources.id = b.source\n ) AS \"source!: Source\",\n b.remote_id,\n b.is_deleted,\n b.pages\n FROM books b\n WHERE b.source = $1 AND b.remote_id = $2\n ", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "id", - "type_info": "Int4" - }, - { - "ordinal": 1, - "name": "title", - "type_info": "Varchar" - }, - { - "ordinal": 2, - "name": "lang", - "type_info": "Varchar" - }, - { - "ordinal": 3, - "name": "file_type", - "type_info": "Varchar" - }, - { - "ordinal": 4, - "name": "year", - "type_info": "Int2" - }, - { - "ordinal": 5, - "name": "available_types!: Vec", - "type_info": "TextArray" - }, - { - "ordinal": 6, - "name": "uploaded", - "type_info": "Date" - }, - { - "ordinal": 7, - "name": "authors!: Vec", - "type_info": "Jsonb" - }, - { - "ordinal": 8, - "name": "translators!: Vec", - "type_info": "Jsonb" - }, - { - "ordinal": 9, - "name": "sequences!: Vec", - "type_info": "Jsonb" - }, - { - "ordinal": 10, - "name": "genres!: Vec", - "type_info": "Jsonb" - }, - { - "ordinal": 11, - "name": "annotation_exists!: bool", - "type_info": "Bool" - }, - { - "ordinal": 12, - "name": "source!: Source", - "type_info": "Jsonb" - }, - { - "ordinal": 13, - "name": "remote_id", - "type_info": "Int4" - }, - { - "ordinal": 14, - "name": "is_deleted", - "type_info": "Bool" - }, - { - "ordinal": 15, - "name": "pages", - "type_info": "Int4" - } - ], - "parameters": { - "Left": [ - "Int2", - "Int4" - ] - }, - "nullable": [ - false, - false, - false, - false, - false, - null, - false, - null, - null, - null, - null, - null, - null, - false, - false, - true - ] - }, - "hash": "e6cf55988b86d72c594915c9e5a015d71106794415fb267d6f71d512e9831012" -} diff --git a/.sqlx/query-ff5b8a130876c7a3821814fb7038ce846f80be9ce07cb655e3b8c7539b084646.json b/.sqlx/query-ff5b8a130876c7a3821814fb7038ce846f80be9ce07cb655e3b8c7539b084646.json new file mode 100644 index 0000000..ff218ab --- /dev/null +++ b/.sqlx/query-ff5b8a130876c7a3821814fb7038ce846f80be9ce07cb655e3b8c7539b084646.json @@ -0,0 +1,276 @@ +{ + "db_name": "PostgreSQL", + "query": "\n SELECT\n b.id,\n b.title,\n b.lang,\n b.file_type,\n b.year,\n CASE WHEN b.file_type = 'fb2' THEN ARRAY['fb2', 'epub', 'mobi', 'fb2zip']::text[] ELSE ARRAY[b.file_type]::text[] END AS \"available_types!: Vec\",\n b.uploaded,\n (\n SELECT\n ARRAY_AGG(\n ROW(\n authors.id,\n authors.first_name,\n authors.last_name,\n authors.middle_name,\n EXISTS(\n SELECT * FROM author_annotations WHERE author = authors.id\n )\n )::author_type\n )\n FROM book_authors\n JOIN authors ON authors.id = book_authors.author\n WHERE book_authors.book = b.id\n ) AS \"authors!: Vec\",\n (\n SELECT\n ARRAY_AGG(\n ROW(\n authors.id,\n authors.first_name,\n authors.last_name,\n authors.middle_name,\n EXISTS(\n SELECT * FROM author_annotations WHERE author = authors.id\n )\n )::author_type\n )\n FROM translations\n JOIN authors ON authors.id = translations.author\n WHERE translations.book = b.id\n ) AS \"translators!: Vec\",\n (\n SELECT\n ARRAY_AGG(\n ROW(\n sequences.id,\n sequences.name\n )::sequence_type\n )\n FROM book_sequences\n JOIN sequences ON sequences.id = book_sequences.sequence\n WHERE book_sequences.book = b.id\n ) AS \"sequences!: Vec\",\n (\n SELECT\n ARRAY_AGG(\n ROW(\n genres.id,\n ROW(\n sources.id,\n sources.name\n )::source_type,\n genres.remote_id,\n genres.code,\n genres.description,\n genres.meta\n )::genre_type\n )\n FROM book_genres\n JOIN genres ON genres.id = book_genres.genre\n JOIN sources ON sources.id = genres.source\n WHERE book_genres.book = b.id\n ) AS \"genres!: Vec\",\n EXISTS(\n SELECT * FROM book_annotations WHERE book = b.id\n ) AS \"annotation_exists!: bool\",\n (\n SELECT\n ROW(\n sources.id,\n sources.name\n )::source_type\n FROM sources\n WHERE sources.id = b.source\n ) AS \"source!: Source\",\n b.remote_id,\n b.is_deleted,\n b.pages\n FROM books b\n WHERE b.id = $1\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id", + "type_info": "Int4" + }, + { + "ordinal": 1, + "name": "title", + "type_info": "Varchar" + }, + { + "ordinal": 2, + "name": "lang", + "type_info": "Varchar" + }, + { + "ordinal": 3, + "name": "file_type", + "type_info": "Varchar" + }, + { + "ordinal": 4, + "name": "year", + "type_info": "Int2" + }, + { + "ordinal": 5, + "name": "available_types!: Vec", + "type_info": "TextArray" + }, + { + "ordinal": 6, + "name": "uploaded", + "type_info": "Date" + }, + { + "ordinal": 7, + "name": "authors!: Vec", + "type_info": { + "Custom": { + "name": "author_type[]", + "kind": { + "Array": { + "Custom": { + "name": "author_type", + "kind": { + "Composite": [ + [ + "id", + "Int4" + ], + [ + "first_name", + "Varchar" + ], + [ + "last_name", + "Varchar" + ], + [ + "middle_name", + "Varchar" + ], + [ + "annotation_exists", + "Bool" + ] + ] + } + } + } + } + } + } + }, + { + "ordinal": 8, + "name": "translators!: Vec", + "type_info": { + "Custom": { + "name": "author_type[]", + "kind": { + "Array": { + "Custom": { + "name": "author_type", + "kind": { + "Composite": [ + [ + "id", + "Int4" + ], + [ + "first_name", + "Varchar" + ], + [ + "last_name", + "Varchar" + ], + [ + "middle_name", + "Varchar" + ], + [ + "annotation_exists", + "Bool" + ] + ] + } + } + } + } + } + } + }, + { + "ordinal": 9, + "name": "sequences!: Vec", + "type_info": { + "Custom": { + "name": "sequence_type[]", + "kind": { + "Array": { + "Custom": { + "name": "sequence_type", + "kind": { + "Composite": [ + [ + "id", + "Int4" + ], + [ + "name", + "Varchar" + ] + ] + } + } + } + } + } + } + }, + { + "ordinal": 10, + "name": "genres!: Vec", + "type_info": { + "Custom": { + "name": "genre_type[]", + "kind": { + "Array": { + "Custom": { + "name": "genre_type", + "kind": { + "Composite": [ + [ + "id", + "Int4" + ], + [ + "source", + { + "Custom": { + "name": "source_type", + "kind": { + "Composite": [ + [ + "id", + "Int4" + ], + [ + "name", + "Varchar" + ] + ] + } + } + } + ], + [ + "remote_id", + "Int4" + ], + [ + "code", + "Varchar" + ], + [ + "description", + "Varchar" + ], + [ + "meta", + "Varchar" + ] + ] + } + } + } + } + } + } + }, + { + "ordinal": 11, + "name": "annotation_exists!: bool", + "type_info": "Bool" + }, + { + "ordinal": 12, + "name": "source!: Source", + "type_info": { + "Custom": { + "name": "source_type", + "kind": { + "Composite": [ + [ + "id", + "Int4" + ], + [ + "name", + "Varchar" + ] + ] + } + } + } + }, + { + "ordinal": 13, + "name": "remote_id", + "type_info": "Int4" + }, + { + "ordinal": 14, + "name": "is_deleted", + "type_info": "Bool" + }, + { + "ordinal": 15, + "name": "pages", + "type_info": "Int4" + } + ], + "parameters": { + "Left": [ + "Int4" + ] + }, + "nullable": [ + false, + false, + false, + false, + false, + null, + false, + null, + null, + null, + null, + null, + null, + false, + false, + true + ] + }, + "hash": "ff5b8a130876c7a3821814fb7038ce846f80be9ce07cb655e3b8c7539b084646" +} diff --git a/Cargo.lock b/Cargo.lock index b49cb26..91aec18 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -256,6 +256,7 @@ dependencies = [ "sentry", "sentry-tracing", "serde", + "serde_json", "sqlx", "tokio", "tower-http 0.6.2", diff --git a/Cargo.toml b/Cargo.toml index e486698..6167a0c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ axum = { version = "0.7.9", features = ["json"] } axum-extra = { version ="0.9.6", features = ["query"] } axum-prometheus = "0.7.0" serde = { version = "1.0.216", features = ["derive"] } +serde_json = { version = "1.0.134", features = ["raw_value"] } sentry = { version = "0.35.0", features = ["debug-images"] } diff --git a/src/serializers/author.rs b/src/serializers/author.rs index e08813a..cbc8dda 100644 --- a/src/serializers/author.rs +++ b/src/serializers/author.rs @@ -5,6 +5,7 @@ use super::date::naive_date_serializer; use super::sequence::Sequence; #[derive(sqlx::FromRow, sqlx::Type, Serialize)] +#[sqlx(type_name = "author_type")] pub struct Author { pub id: i32, pub first_name: String, @@ -23,7 +24,7 @@ pub struct AuthorBook { pub available_types: Vec, #[serde(serialize_with = "naive_date_serializer::serialize")] pub uploaded: NaiveDate, - pub translators: sqlx::types::Json>, - pub sequences: sqlx::types::Json>, + pub translators: Vec, + pub sequences: Vec, pub annotation_exists: bool, } diff --git a/src/serializers/book.rs b/src/serializers/book.rs index 3bf5118..a342505 100644 --- a/src/serializers/book.rs +++ b/src/serializers/book.rs @@ -81,8 +81,8 @@ pub struct Book { pub available_types: Vec, #[serde(serialize_with = "naive_date_serializer::serialize")] pub uploaded: NaiveDate, - pub authors: sqlx::types::Json>, - pub translators: sqlx::types::Json>, - pub sequences: sqlx::types::Json>, + pub authors: Vec, + pub translators: Vec, + pub sequences: Vec, pub annotation_exists: bool, } diff --git a/src/serializers/genre.rs b/src/serializers/genre.rs index f33344a..b656637 100644 --- a/src/serializers/genre.rs +++ b/src/serializers/genre.rs @@ -3,6 +3,7 @@ use serde::{Deserialize, Serialize}; use super::source::Source; #[derive(sqlx::FromRow, sqlx::Type, Serialize)] +#[sqlx(type_name = "genre_type")] pub struct Genre { pub id: i32, pub source: Source, diff --git a/src/serializers/sequence.rs b/src/serializers/sequence.rs index cef544e..8b092e5 100644 --- a/src/serializers/sequence.rs +++ b/src/serializers/sequence.rs @@ -5,6 +5,7 @@ use super::author::Author; use super::date::naive_date_serializer; #[derive(sqlx::FromRow, sqlx::Type, Serialize)] +#[sqlx(type_name = "sequence_type")] pub struct Sequence { pub id: i32, pub name: String, @@ -20,8 +21,8 @@ pub struct SequenceBook { pub available_types: Vec, #[serde(serialize_with = "naive_date_serializer::serialize")] pub uploaded: NaiveDate, - pub authors: sqlx::types::Json>, - pub translators: sqlx::types::Json>, + pub authors: Vec, + pub translators: Vec, pub annotation_exists: bool, pub position: i32, } diff --git a/src/serializers/source.rs b/src/serializers/source.rs index d30253d..d896b2d 100644 --- a/src/serializers/source.rs +++ b/src/serializers/source.rs @@ -1,6 +1,7 @@ use serde::Serialize; #[derive(sqlx::FromRow, sqlx::Type, Serialize)] +#[sqlx(type_name = "source_type")] pub struct Source { pub id: i32, pub name: String, diff --git a/src/serializers/translator.rs b/src/serializers/translator.rs index 35f333d..080ff43 100644 --- a/src/serializers/translator.rs +++ b/src/serializers/translator.rs @@ -15,7 +15,7 @@ pub struct TranslatorBook { pub available_types: Vec, #[serde(serialize_with = "naive_date_serializer::serialize")] pub uploaded: NaiveDate, - pub authors: sqlx::types::Json>, - pub sequences: sqlx::types::Json>, + pub authors: Vec, + pub sequences: Vec, pub annotation_exists: bool, } diff --git a/src/views/authors.rs b/src/views/authors.rs index 6a81396..165b301 100644 --- a/src/views/authors.rs +++ b/src/views/authors.rs @@ -216,16 +216,16 @@ async fn get_author_books( b.uploaded, ( SELECT - JSONB_AGG( - JSONB_BUILD_OBJECT( - 'id', authors.id, - 'first_name', authors.first_name, - 'last_name', authors.last_name, - 'middle_name', authors.middle_name, - 'annotation_exists', EXISTS( + ARRAY_AGG( + ROW( + authors.id, + authors.first_name, + authors.last_name, + authors.middle_name, + EXISTS( SELECT * FROM author_annotations WHERE author = authors.id ) - ) + )::author_type ) FROM translations JOIN authors ON authors.id = translations.author @@ -233,11 +233,11 @@ async fn get_author_books( ) AS "translators!: Vec", ( SELECT - JSONB_AGG( - JSONB_BUILD_OBJECT( - 'id', sequences.id, - 'name', sequences.name - ) + ARRAY_AGG( + ROW( + sequences.id, + sequences.name + )::sequence_type ) FROM book_sequences JOIN sequences ON sequences.id = book_sequences.sequence diff --git a/src/views/books.rs b/src/views/books.rs index c11aefc..35f504a 100644 --- a/src/views/books.rs +++ b/src/views/books.rs @@ -62,16 +62,16 @@ pub async fn get_books( b.uploaded, ( SELECT - JSONB_AGG( - JSONB_BUILD_OBJECT( - 'id', authors.id, - 'first_name', authors.first_name, - 'last_name', authors.last_name, - 'middle_name', authors.middle_name, - 'annotation_exists', EXISTS( + ARRAY_AGG( + ROW( + authors.id, + authors.first_name, + authors.last_name, + authors.middle_name, + EXISTS( SELECT * FROM author_annotations WHERE author = authors.id ) - ) + )::author_type ) FROM book_authors JOIN authors ON authors.id = book_authors.author @@ -79,16 +79,16 @@ pub async fn get_books( ) AS "authors!: Vec", ( SELECT - JSONB_AGG( - JSONB_BUILD_OBJECT( - 'id', authors.id, - 'first_name', authors.first_name, - 'last_name', authors.last_name, - 'middle_name', authors.middle_name, - 'annotation_exists', EXISTS( + ARRAY_AGG( + ROW( + authors.id, + authors.first_name, + authors.last_name, + authors.middle_name, + EXISTS( SELECT * FROM author_annotations WHERE author = authors.id ) - ) + )::author_type ) FROM translations JOIN authors ON authors.id = translations.author @@ -96,11 +96,11 @@ pub async fn get_books( ) AS "translators!: Vec", ( SELECT - JSONB_AGG( - JSONB_BUILD_OBJECT( - 'id', sequences.id, - 'name', sequences.name - ) + ARRAY_AGG( + ROW( + sequences.id, + sequences.name + )::sequence_type ) FROM book_sequences JOIN sequences ON sequences.id = book_sequences.sequence @@ -111,10 +111,10 @@ pub async fn get_books( ) AS "annotation_exists!: bool", ( SELECT - JSONB_BUILD_OBJECT( - 'id', sources.id, - 'name', sources.name - ) + ROW( + sources.id, + sources.name + )::source_type FROM sources WHERE sources.id = b.source ) AS "source!: Source", @@ -245,16 +245,16 @@ pub async fn get_random_book( b.uploaded, ( SELECT - JSONB_AGG( - JSONB_BUILD_OBJECT( - 'id', authors.id, - 'first_name', authors.first_name, - 'last_name', authors.last_name, - 'middle_name', authors.middle_name, - 'annotation_exists', EXISTS( + ARRAY_AGG( + ROW( + authors.id, + authors.first_name, + authors.last_name, + authors.middle_name, + EXISTS( SELECT * FROM author_annotations WHERE author = authors.id ) - ) + )::author_type ) FROM book_authors JOIN authors ON authors.id = book_authors.author @@ -262,16 +262,16 @@ pub async fn get_random_book( ) AS "authors!: Vec", ( SELECT - JSONB_AGG( - JSONB_BUILD_OBJECT( - 'id', authors.id, - 'first_name', authors.first_name, - 'last_name', authors.last_name, - 'middle_name', authors.middle_name, - 'annotation_exists', EXISTS( + ARRAY_AGG( + ROW( + authors.id, + authors.first_name, + authors.last_name, + authors.middle_name, + EXISTS( SELECT * FROM author_annotations WHERE author = authors.id ) - ) + )::author_type ) FROM translations JOIN authors ON authors.id = translations.author @@ -279,11 +279,11 @@ pub async fn get_random_book( ) AS "translators!: Vec", ( SELECT - JSONB_AGG( - JSONB_BUILD_OBJECT( - 'id', sequences.id, - 'name', sequences.name - ) + ARRAY_AGG( + ROW( + sequences.id, + sequences.name + )::sequence_type ) FROM book_sequences JOIN sequences ON sequences.id = book_sequences.sequence @@ -291,17 +291,18 @@ pub async fn get_random_book( ) AS "sequences!: Vec", ( SELECT - JSONB_AGG( - JSONB_BUILD_OBJECT( - 'id', genres.id, - 'code', genres.code, - 'description', genres.description, - 'meta', genres.meta, - 'source', JSONB_BUILD_OBJECT( - 'id', sources.id, - 'name', sources.name - ) - ) + ARRAY_AGG( + ROW( + genres.id, + ROW( + sources.id, + sources.name + )::source_type, + genres.remote_id, + genres.code, + genres.description, + genres.meta + )::genre_type ) FROM book_genres JOIN genres ON genres.id = book_genres.genre @@ -313,10 +314,10 @@ pub async fn get_random_book( ) AS "annotation_exists!: bool", ( SELECT - JSONB_BUILD_OBJECT( - 'id', sources.id, - 'name', sources.name - ) + ROW( + sources.id, + sources.name + )::source_type FROM sources WHERE sources.id = b.source ) AS "source!: Source", @@ -353,16 +354,16 @@ pub async fn get_remote_book( b.uploaded, ( SELECT - JSONB_AGG( - JSONB_BUILD_OBJECT( - 'id', authors.id, - 'first_name', authors.first_name, - 'last_name', authors.last_name, - 'middle_name', authors.middle_name, - 'annotation_exists', EXISTS( + ARRAY_AGG( + ROW( + authors.id, + authors.first_name, + authors.last_name, + authors.middle_name, + EXISTS( SELECT * FROM author_annotations WHERE author = authors.id ) - ) + )::author_type ) FROM book_authors JOIN authors ON authors.id = book_authors.author @@ -370,16 +371,16 @@ pub async fn get_remote_book( ) AS "authors!: Vec", ( SELECT - JSONB_AGG( - JSONB_BUILD_OBJECT( - 'id', authors.id, - 'first_name', authors.first_name, - 'last_name', authors.last_name, - 'middle_name', authors.middle_name, - 'annotation_exists', EXISTS( + ARRAY_AGG( + ROW( + authors.id, + authors.first_name, + authors.last_name, + authors.middle_name, + EXISTS( SELECT * FROM author_annotations WHERE author = authors.id ) - ) + )::author_type ) FROM translations JOIN authors ON authors.id = translations.author @@ -387,11 +388,11 @@ pub async fn get_remote_book( ) AS "translators!: Vec", ( SELECT - JSONB_AGG( - JSONB_BUILD_OBJECT( - 'id', sequences.id, - 'name', sequences.name - ) + ARRAY_AGG( + ROW( + sequences.id, + sequences.name + )::sequence_type ) FROM book_sequences JOIN sequences ON sequences.id = book_sequences.sequence @@ -399,17 +400,18 @@ pub async fn get_remote_book( ) AS "sequences!: Vec", ( SELECT - JSONB_AGG( - JSONB_BUILD_OBJECT( - 'id', genres.id, - 'code', genres.code, - 'description', genres.description, - 'meta', genres.meta, - 'source', JSONB_BUILD_OBJECT( - 'id', sources.id, - 'name', sources.name - ) - ) + ARRAY_AGG( + ROW( + genres.id, + ROW( + sources.id, + sources.name + )::source_type, + remote_id, + genres.code, + genres.description, + genres.meta + )::genre_type ) FROM book_genres JOIN genres ON genres.id = book_genres.genre @@ -421,10 +423,10 @@ pub async fn get_remote_book( ) AS "annotation_exists!: bool", ( SELECT - JSONB_BUILD_OBJECT( - 'id', sources.id, - 'name', sources.name - ) + ROW( + sources.id, + sources.name + )::source_type FROM sources WHERE sources.id = b.source ) AS "source!: Source", @@ -491,16 +493,16 @@ pub async fn search_books( b.uploaded, ( SELECT - JSONB_AGG( - JSONB_BUILD_OBJECT( - 'id', authors.id, - 'first_name', authors.first_name, - 'last_name', authors.last_name, - 'middle_name', authors.middle_name, - 'annotation_exists', EXISTS( + ARRAY_AGG( + ROW( + authors.id, + authors.first_name, + authors.last_name, + authors.middle_name, + EXISTS( SELECT * FROM author_annotations WHERE author = authors.id ) - ) + )::author_type ) FROM book_authors JOIN authors ON authors.id = book_authors.author @@ -508,16 +510,16 @@ pub async fn search_books( ) AS "authors!: Vec", ( SELECT - JSONB_AGG( - JSONB_BUILD_OBJECT( - 'id', authors.id, - 'first_name', authors.first_name, - 'last_name', authors.last_name, - 'middle_name', authors.middle_name, - 'annotation_exists', EXISTS( + ARRAY_AGG( + ROW( + authors.id, + authors.first_name, + authors.last_name, + authors.middle_name, + EXISTS( SELECT * FROM author_annotations WHERE author = authors.id ) - ) + )::author_type ) FROM translations JOIN authors ON authors.id = translations.author @@ -525,11 +527,11 @@ pub async fn search_books( ) AS "translators!: Vec", ( SELECT - JSONB_AGG( - JSONB_BUILD_OBJECT( - 'id', sequences.id, - 'name', sequences.name - ) + ARRAY_AGG( + ROW( + sequences.id, + sequences.name + )::sequence_type ) FROM book_sequences JOIN sequences ON sequences.id = book_sequences.sequence @@ -573,16 +575,16 @@ pub async fn get_book(db: Database, Path(book_id): Path) -> impl IntoRespon b.uploaded, ( SELECT - JSONB_AGG( - JSONB_BUILD_OBJECT( - 'id', authors.id, - 'first_name', authors.first_name, - 'last_name', authors.last_name, - 'middle_name', authors.middle_name, - 'annotation_exists', EXISTS( + ARRAY_AGG( + ROW( + authors.id, + authors.first_name, + authors.last_name, + authors.middle_name, + EXISTS( SELECT * FROM author_annotations WHERE author = authors.id ) - ) + )::author_type ) FROM book_authors JOIN authors ON authors.id = book_authors.author @@ -590,16 +592,16 @@ pub async fn get_book(db: Database, Path(book_id): Path) -> impl IntoRespon ) AS "authors!: Vec", ( SELECT - JSONB_AGG( - JSONB_BUILD_OBJECT( - 'id', authors.id, - 'first_name', authors.first_name, - 'last_name', authors.last_name, - 'middle_name', authors.middle_name, - 'annotation_exists', EXISTS( + ARRAY_AGG( + ROW( + authors.id, + authors.first_name, + authors.last_name, + authors.middle_name, + EXISTS( SELECT * FROM author_annotations WHERE author = authors.id ) - ) + )::author_type ) FROM translations JOIN authors ON authors.id = translations.author @@ -607,11 +609,11 @@ pub async fn get_book(db: Database, Path(book_id): Path) -> impl IntoRespon ) AS "translators!: Vec", ( SELECT - JSONB_AGG( - JSONB_BUILD_OBJECT( - 'id', sequences.id, - 'name', sequences.name - ) + ARRAY_AGG( + ROW( + sequences.id, + sequences.name + )::sequence_type ) FROM book_sequences JOIN sequences ON sequences.id = book_sequences.sequence @@ -619,17 +621,18 @@ pub async fn get_book(db: Database, Path(book_id): Path) -> impl IntoRespon ) AS "sequences!: Vec", ( SELECT - JSONB_AGG( - JSONB_BUILD_OBJECT( - 'id', genres.id, - 'code', genres.code, - 'description', genres.description, - 'meta', genres.meta, - 'source', JSONB_BUILD_OBJECT( - 'id', sources.id, - 'name', sources.name - ) - ) + ARRAY_AGG( + ROW( + genres.id, + ROW( + sources.id, + sources.name + )::source_type, + genres.remote_id, + genres.code, + genres.description, + genres.meta + )::genre_type ) FROM book_genres JOIN genres ON genres.id = book_genres.genre @@ -641,10 +644,10 @@ pub async fn get_book(db: Database, Path(book_id): Path) -> impl IntoRespon ) AS "annotation_exists!: bool", ( SELECT - JSONB_BUILD_OBJECT( - 'id', sources.id, - 'name', sources.name - ) + ROW( + sources.id, + sources.name + )::source_type FROM sources WHERE sources.id = b.source ) AS "source!: Source", diff --git a/src/views/genres.rs b/src/views/genres.rs index c5b23eb..3591fcd 100644 --- a/src/views/genres.rs +++ b/src/views/genres.rs @@ -39,10 +39,10 @@ pub async fn get_genres( genres.meta, ( SELECT - JSONB_BUILD_OBJECT( - 'id', sources.id, - 'name', sources.name - ) + ROW( + sources.id, + sources.name + )::source_type FROM sources WHERE sources.id = genres.source ) AS "source!: Source" @@ -76,10 +76,10 @@ pub async fn get_genre_metas(db: Database) -> impl IntoResponse { genres.meta, ( SELECT - JSONB_BUILD_OBJECT( - 'id', sources.id, - 'name', sources.name - ) + ROW( + sources.id, + sources.name + )::source_type FROM sources WHERE sources.id = genres.source ) AS "source!: Source" diff --git a/src/views/sequences.rs b/src/views/sequences.rs index 4a840cd..fbfa35d 100644 --- a/src/views/sequences.rs +++ b/src/views/sequences.rs @@ -215,16 +215,16 @@ async fn get_sequence_books( b.uploaded, ( SELECT - JSONB_AGG( - JSONB_BUILD_OBJECT( - 'id', authors.id, - 'first_name', authors.first_name, - 'last_name', authors.last_name, - 'middle_name', authors.middle_name, - 'annotation_exists', EXISTS( + ARRAY_AGG( + ROW( + authors.id, + authors.first_name, + authors.last_name, + authors.middle_name, + EXISTS( SELECT * FROM author_annotations WHERE author = authors.id ) - ) + )::author_type ) FROM book_authors JOIN authors ON authors.id = book_authors.author @@ -232,16 +232,16 @@ async fn get_sequence_books( ) AS "authors!: Vec", ( SELECT - JSONB_AGG( - JSONB_BUILD_OBJECT( - 'id', authors.id, - 'first_name', authors.first_name, - 'last_name', authors.last_name, - 'middle_name', authors.middle_name, - 'annotation_exists', EXISTS( + ARRAY_AGG( + ROW( + authors.id, + authors.first_name, + authors.last_name, + authors.middle_name, + EXISTS( SELECT * FROM author_annotations WHERE author = authors.id ) - ) + )::author_type ) FROM translations JOIN authors ON authors.id = translations.author diff --git a/src/views/translators.rs b/src/views/translators.rs index 588772a..b313305 100644 --- a/src/views/translators.rs +++ b/src/views/translators.rs @@ -88,16 +88,16 @@ async fn get_translated_books( b.uploaded, ( SELECT - JSONB_AGG( - JSONB_BUILD_OBJECT( - 'id', authors.id, - 'first_name', authors.first_name, - 'last_name', authors.last_name, - 'middle_name', authors.middle_name, - 'annotation_exists', EXISTS( + ARRAY_AGG( + ROW( + authors.id, + authors.first_name, + authors.last_name, + authors.middle_name, + EXISTS( SELECT * FROM author_annotations WHERE author = authors.id ) - ) + )::author_type ) FROM book_authors JOIN authors ON authors.id = book_authors.author @@ -105,11 +105,11 @@ async fn get_translated_books( ) AS "authors!: Vec", ( SELECT - JSONB_AGG( - JSONB_BUILD_OBJECT( - 'id', sequences.id, - 'name', sequences.name - ) + ARRAY_AGG( + ROW( + sequences.id, + sequences.name + )::sequence_type ) FROM book_sequences JOIN sequences ON sequences.id = book_sequences.sequence