Skip to content

Commit cb9946b

Browse files
committed
move adjoints into functors table
1 parent 31b1907 commit cb9946b

7 files changed

Lines changed: 42 additions & 75 deletions

File tree

databases/catdat/schema/007_functors.sql

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@ CREATE TABLE functors (
22
id TEXT PRIMARY KEY,
33
source TEXT NOT NULL,
44
target TEXT NOT NULL,
5+
left_adjoint TEXT,
6+
UNIQUE (id, source, target),
7+
FOREIGN KEY (id) REFERENCES structures (id) ON DELETE CASCADE,
58
FOREIGN KEY (source) REFERENCES categories (id) ON DELETE CASCADE,
69
FOREIGN KEY (target) REFERENCES categories (id) ON DELETE CASCADE,
7-
FOREIGN KEY (id) REFERENCES structures (id) ON DELETE CASCADE
10+
FOREIGN KEY (left_adjoint, target, source)
11+
REFERENCES functors (id, source, target)
12+
ON DELETE CASCADE
813
);
914

1015
CREATE TRIGGER trg_functor_type_check

databases/catdat/schema/008_adjoint-functors.sql

Lines changed: 0 additions & 26 deletions
This file was deleted.
File renamed without changes.

databases/catdat/scripts/seed.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ function clear_all_tables() {
6868

6969
db.prepare(`DELETE FROM source_assumptions`).run()
7070
db.prepare(`DELETE FROM target_assumptions`).run()
71-
db.prepare(`DELETE FROM adjoint_functors`).run()
7271

7372
db.prepare(`DELETE FROM assumptions`).run()
7473
db.prepare(`DELETE FROM conclusions`).run()
@@ -279,20 +278,16 @@ function insert_category(category: CategoryYaml) {
279278
*/
280279
function insert_functor(functor: FunctorYaml) {
281280
const functor_insert = db.prepare(
282-
`INSERT INTO functors (id, source, target) VALUES (?, ?, ?)`,
281+
`INSERT INTO functors (id, source, target, left_adjoint)
282+
VALUES (?, ?, ?, ?)`,
283283
)
284284

285-
const adjoint_insert = db.prepare(
286-
`INSERT INTO adjoint_functors (left_adjoint, right_adjoint)
287-
VALUES (?, ?)
288-
ON CONFLICT (left_adjoint, right_adjoint) DO NOTHING`,
285+
functor_insert.run(
286+
functor.id,
287+
functor.source,
288+
functor.target,
289+
functor.left_adjoint || null,
289290
)
290-
291-
functor_insert.run(functor.id, functor.source, functor.target)
292-
293-
if (functor.left_adjoint) {
294-
adjoint_insert.run(functor.left_adjoint, functor.id)
295-
}
296291
}
297292

298293
/**

src/lib/commons/types.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,17 @@ export type CategorySpecificDisplay = {
3131

3232
export type FunctorSpecificDisplay = {
3333
source: string
34-
target: string
3534
source_name: string
36-
target_name: string
3735
source_notation: string
36+
target: string
37+
target_name: string
3838
target_notation: string
39+
left_adjoint: string | null
40+
left_adjoint_name: string | null
41+
left_adjoint_notation: string | null
42+
right_adjoint: string | null
43+
right_adjoint_name: string | null
44+
right_adjoint_notation: string | null
3945
}
4046

4147
export type TagObject = { tag: string }

src/routes/functor/[id]/+page.server.ts

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { FunctorSpecificDisplay, RelatedStructure } from '$lib/commons/types'
2-
import { batch } from '$lib/server/db.catdat'
1+
import type { FunctorSpecificDisplay } from '$lib/commons/types'
2+
import { query } from '$lib/server/db.catdat'
33
import { fetch_structure } from '$lib/server/fetchers/structure'
44
import { render_nested_formulas } from '$lib/server/formulas'
55
import { error } from '@sveltejs/kit'
@@ -20,9 +20,7 @@ export const load = (event) => {
2020
comments,
2121
} = fetch_structure('functor', id)
2222

23-
const { results, err } = batch<
24-
[FunctorSpecificDisplay, RelatedStructure, RelatedStructure]
25-
>([
23+
const { rows: functors, err } = query<FunctorSpecificDisplay>(
2624
// specific information for the functor
2725
sql`
2826
SELECT
@@ -31,39 +29,28 @@ export const load = (event) => {
3129
source.name AS source_name,
3230
source.notation AS source_notation,
3331
target.name AS target_name,
34-
target.notation AS target_notation
32+
target.notation AS target_notation,
33+
la.id AS left_adjoint,
34+
la.name AS left_adjoint_name,
35+
la.notation AS left_adjoint_notation,
36+
ra.id AS right_adjoint,
37+
ra.name AS right_adjoint_name,
38+
ra.notation AS right_adjoint_notation
3539
FROM functors f
3640
INNER JOIN structures AS source ON source.id = f.source
3741
INNER JOIN structures AS target ON target.id = f.target
42+
LEFT JOIN structures AS la ON la.id = f.left_adjoint
43+
LEFT JOIN functors AS rf ON rf.left_adjoint = f.id
44+
LEFT JOIN structures AS ra ON ra.id = rf.id
3845
WHERE f.id = ${id}
3946
`,
40-
// left adjoint functor
41-
sql`
42-
SELECT f.id, f.name, f.notation
43-
FROM adjoint_functors a
44-
INNER JOIN structures f ON f.id = a.left_adjoint
45-
WHERE a.right_adjoint = ${id}
46-
`,
47-
// right adjoint functor
48-
sql`
49-
SELECT f.id, f.name, f.notation
50-
FROM adjoint_functors a
51-
INNER JOIN structures f ON f.id = a.right_adjoint
52-
WHERE a.left_adjoint = ${id}
53-
`,
54-
])
47+
)
5548

5649
if (err) error(500, 'Could not load functor')
5750

58-
const [functors, left_adjoints, right_adjoints] = results
59-
6051
if (!functors.length) error(404, `Could not find functor with ID '${id}'`)
6152

62-
const functor = {
63-
...functors[0],
64-
left_adjoint: left_adjoints.at(0),
65-
right_adjoint: right_adjoints.at(0),
66-
}
53+
const functor = functors[0]
6754

6855
return render_nested_formulas({
6956
structure,

src/routes/functor/[id]/+page.svelte

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
<li>
2121
<strong>Left adjoint:</strong>
2222
<a
23-
href="/functor/{data.functor.left_adjoint.id}"
24-
aria-label={data.functor.left_adjoint.name}
23+
href="/functor/{data.functor.left_adjoint}"
24+
aria-label={data.functor.left_adjoint_name}
2525
>
26-
{@html data.functor.left_adjoint.notation}
26+
{@html data.functor.left_adjoint_notation}
2727
</a>
2828
</li>
2929
{/if}
@@ -32,10 +32,10 @@
3232
<li>
3333
<strong>Right adjoint:</strong>
3434
<a
35-
href="/functor/{data.functor.right_adjoint.id}"
36-
aria-label={data.functor.right_adjoint.name}
35+
href="/functor/{data.functor.right_adjoint}"
36+
aria-label={data.functor.right_adjoint_name}
3737
>
38-
{@html data.functor.right_adjoint.notation}
38+
{@html data.functor.right_adjoint_notation}
3939
</a>
4040
</li>
4141
{/if}

0 commit comments

Comments
 (0)