~bigbes/core-go

ref: 465a6f71354e94f54f4545291ee747784a3e090b core-go/database/ql.go -rw-r--r-- 2.5 KiB
72c2f060 — Simon Ser 3 years ago
database: specify field name for graphql.CollectedField

Newer versions of the graphql package add new fields to this struct.
This results in errors:

    database/ql.go:40:4: too few values in struct literal of type graphql.CollectedField
    database/ql.go:71:4: too few values in struct literal of type graphql.CollectedField
e7ae287d — Simon Ser 4 years ago
database: always include table name in SELECT

When JOINs are performed on the auto-generated SELECT query,
multiple tables may have the same field names. For instance, in
lists.sr.ht the "list" and "subscription" tables both have an "id"
column. When performing a "mailingLists" GraphQL query this results
in this error:

    pq: column reference "id" is ambiguous

The old query looks like this:

    SELECT "description", "name", "id", "owner_id", "updated", COALESCE(
    access.permissions,
    CASE WHEN list.owner_id = $1
    THEN $2
    ELSE CASE WHEN sub.id IS NOT NULL
    	THEN list.subscriber_permissions
    	ELSE null END
    END,
    list.nonsubscriber_permissions | list.account_permissions), access.id AS access_id, sub.id AS subscription_id FROM list LEFT JOIN access ON
    access.list_id = list.id AND
    access.user_id = $3 LEFT JOIN subscription sub ON
    sub.list_id = list.id AND
    sub.user_id = $4 WHERE list.owner_id = $5 ORDER BY "updated" DESC LIMIT 26

The new query looks like this:

    SELECT "description", "name", "list"."id", "list"."owner_id", "list"."updated", COALESCE(
    access.permissions,
    CASE WHEN list.owner_id = $1
    THEN $2
    ELSE CASE WHEN sub.id IS NOT NULL
    	THEN list.subscriber_permissions
    	ELSE null END
    END,
    list.nonsubscriber_permissions | list.account_permissions), access.id AS access_id, sub.id AS subscription_id FROM list LEFT JOIN access ON
    access.list_id = list.id AND
    access.user_id = $3 LEFT JOIN subscription sub ON
    sub.list_id = list.id AND
    sub.user_id = $4 WHERE list.owner_id = $5 ORDER BY "updated" DESC LIMIT 26
07056613 — Drew DeVault 5 years ago
database: expand field map for composite fields

This allows models to fetch multiple SQL columns to obtain the data
necessary to compute a single composite GraphQL field, while still
avoiding unnecessary fetches if those fields are not queried.
1d2a30cb — Drew DeVault 5 years ago
Import GQL server interfaces from gql.sr.ht