| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660 |
- package postgres
- import (
- "context"
- "encoding/json"
- "errors"
- "fmt"
- "time"
- "github.com/jackc/pgx/v5"
- )
- type ResourceMap struct {
- ID string
- PublicID string
- Code string
- Name string
- Status string
- Description *string
- CurrentVersionID *string
- CreatedAt time.Time
- UpdatedAt time.Time
- }
- type ResourceMapVersion struct {
- ID string
- PublicID string
- MapID string
- VersionCode string
- Status string
- MapmetaURL string
- TilesRootURL string
- PublishedAssetRoot *string
- BoundsJSON json.RawMessage
- MetadataJSON json.RawMessage
- CreatedAt time.Time
- UpdatedAt time.Time
- }
- type ResourcePlayfield struct {
- ID string
- PublicID string
- Code string
- Name string
- Kind string
- Status string
- Description *string
- CurrentVersionID *string
- CreatedAt time.Time
- UpdatedAt time.Time
- }
- type ResourcePlayfieldVersion struct {
- ID string
- PublicID string
- PlayfieldID string
- VersionCode string
- Status string
- SourceType string
- SourceURL string
- PublishedAssetRoot *string
- ControlCount *int
- BoundsJSON json.RawMessage
- MetadataJSON json.RawMessage
- CreatedAt time.Time
- UpdatedAt time.Time
- }
- type ResourcePack struct {
- ID string
- PublicID string
- Code string
- Name string
- Status string
- Description *string
- CurrentVersionID *string
- CreatedAt time.Time
- UpdatedAt time.Time
- }
- type ResourcePackVersion struct {
- ID string
- PublicID string
- ResourcePackID string
- VersionCode string
- Status string
- ContentEntryURL *string
- AudioRootURL *string
- ThemeProfileCode *string
- PublishedAssetRoot *string
- MetadataJSON json.RawMessage
- CreatedAt time.Time
- UpdatedAt time.Time
- }
- type CreateResourceMapParams struct {
- PublicID string
- Code string
- Name string
- Status string
- Description *string
- }
- type CreateResourceMapVersionParams struct {
- PublicID string
- MapID string
- VersionCode string
- Status string
- MapmetaURL string
- TilesRootURL string
- PublishedAssetRoot *string
- BoundsJSON map[string]any
- MetadataJSON map[string]any
- }
- type CreateResourcePlayfieldParams struct {
- PublicID string
- Code string
- Name string
- Kind string
- Status string
- Description *string
- }
- type CreateResourcePlayfieldVersionParams struct {
- PublicID string
- PlayfieldID string
- VersionCode string
- Status string
- SourceType string
- SourceURL string
- PublishedAssetRoot *string
- ControlCount *int
- BoundsJSON map[string]any
- MetadataJSON map[string]any
- }
- type CreateResourcePackParams struct {
- PublicID string
- Code string
- Name string
- Status string
- Description *string
- }
- type CreateResourcePackVersionParams struct {
- PublicID string
- ResourcePackID string
- VersionCode string
- Status string
- ContentEntryURL *string
- AudioRootURL *string
- ThemeProfileCode *string
- PublishedAssetRoot *string
- MetadataJSON map[string]any
- }
- func (s *Store) ListResourceMaps(ctx context.Context, limit int) ([]ResourceMap, error) {
- if limit <= 0 || limit > 200 {
- limit = 50
- }
- rows, err := s.pool.Query(ctx, `
- SELECT id, map_public_id, code, name, status, description, current_version_id, created_at, updated_at
- FROM maps
- ORDER BY created_at DESC
- LIMIT $1
- `, limit)
- if err != nil {
- return nil, fmt.Errorf("list resource maps: %w", err)
- }
- defer rows.Close()
- items := []ResourceMap{}
- for rows.Next() {
- item, err := scanResourceMapFromRows(rows)
- if err != nil {
- return nil, err
- }
- items = append(items, *item)
- }
- if err := rows.Err(); err != nil {
- return nil, fmt.Errorf("iterate resource maps: %w", err)
- }
- return items, nil
- }
- func (s *Store) GetResourceMapByPublicID(ctx context.Context, publicID string) (*ResourceMap, error) {
- row := s.pool.QueryRow(ctx, `
- SELECT id, map_public_id, code, name, status, description, current_version_id, created_at, updated_at
- FROM maps
- WHERE map_public_id = $1
- LIMIT 1
- `, publicID)
- return scanResourceMap(row)
- }
- func (s *Store) CreateResourceMap(ctx context.Context, tx Tx, params CreateResourceMapParams) (*ResourceMap, error) {
- row := tx.QueryRow(ctx, `
- INSERT INTO maps (map_public_id, code, name, status, description)
- VALUES ($1, $2, $3, $4, $5)
- RETURNING id, map_public_id, code, name, status, description, current_version_id, created_at, updated_at
- `, params.PublicID, params.Code, params.Name, params.Status, params.Description)
- return scanResourceMap(row)
- }
- func (s *Store) ListResourceMapVersions(ctx context.Context, mapID string) ([]ResourceMapVersion, error) {
- rows, err := s.pool.Query(ctx, `
- SELECT id, version_public_id, map_id, version_code, status, mapmeta_url, tiles_root_url, published_asset_root,
- bounds_jsonb::text, metadata_jsonb::text, created_at, updated_at
- FROM map_versions
- WHERE map_id = $1
- ORDER BY created_at DESC
- `, mapID)
- if err != nil {
- return nil, fmt.Errorf("list resource map versions: %w", err)
- }
- defer rows.Close()
- items := []ResourceMapVersion{}
- for rows.Next() {
- item, err := scanResourceMapVersionFromRows(rows)
- if err != nil {
- return nil, err
- }
- items = append(items, *item)
- }
- if err := rows.Err(); err != nil {
- return nil, fmt.Errorf("iterate resource map versions: %w", err)
- }
- return items, nil
- }
- func (s *Store) GetResourceMapVersionByPublicID(ctx context.Context, mapPublicID, versionPublicID string) (*ResourceMapVersion, error) {
- row := s.pool.QueryRow(ctx, `
- SELECT mv.id, mv.version_public_id, mv.map_id, mv.version_code, mv.status, mv.mapmeta_url, mv.tiles_root_url, mv.published_asset_root,
- mv.bounds_jsonb::text, mv.metadata_jsonb::text, mv.created_at, mv.updated_at
- FROM map_versions mv
- JOIN maps m ON m.id = mv.map_id
- WHERE m.map_public_id = $1
- AND mv.version_public_id = $2
- LIMIT 1
- `, mapPublicID, versionPublicID)
- return scanResourceMapVersion(row)
- }
- func (s *Store) CreateResourceMapVersion(ctx context.Context, tx Tx, params CreateResourceMapVersionParams) (*ResourceMapVersion, error) {
- boundsJSON, err := marshalJSONMap(params.BoundsJSON)
- if err != nil {
- return nil, fmt.Errorf("marshal map bounds: %w", err)
- }
- metadataJSON, err := marshalJSONMap(params.MetadataJSON)
- if err != nil {
- return nil, fmt.Errorf("marshal map metadata: %w", err)
- }
- row := tx.QueryRow(ctx, `
- INSERT INTO map_versions (
- version_public_id, map_id, version_code, status, mapmeta_url, tiles_root_url,
- published_asset_root, bounds_jsonb, metadata_jsonb
- )
- VALUES ($1, $2, $3, $4, $5, $6, $7, $8::jsonb, $9::jsonb)
- RETURNING id, version_public_id, map_id, version_code, status, mapmeta_url, tiles_root_url, published_asset_root,
- bounds_jsonb::text, metadata_jsonb::text, created_at, updated_at
- `, params.PublicID, params.MapID, params.VersionCode, params.Status, params.MapmetaURL, params.TilesRootURL, params.PublishedAssetRoot, boundsJSON, metadataJSON)
- return scanResourceMapVersion(row)
- }
- func (s *Store) SetResourceMapCurrentVersion(ctx context.Context, tx Tx, mapID, versionID string) error {
- _, err := tx.Exec(ctx, `UPDATE maps SET current_version_id = $2 WHERE id = $1`, mapID, versionID)
- if err != nil {
- return fmt.Errorf("set resource map current version: %w", err)
- }
- return nil
- }
- func (s *Store) ListResourcePlayfields(ctx context.Context, limit int) ([]ResourcePlayfield, error) {
- if limit <= 0 || limit > 200 {
- limit = 50
- }
- rows, err := s.pool.Query(ctx, `
- SELECT id, playfield_public_id, code, name, kind, status, description, current_version_id, created_at, updated_at
- FROM playfields
- ORDER BY created_at DESC
- LIMIT $1
- `, limit)
- if err != nil {
- return nil, fmt.Errorf("list resource playfields: %w", err)
- }
- defer rows.Close()
- items := []ResourcePlayfield{}
- for rows.Next() {
- item, err := scanResourcePlayfieldFromRows(rows)
- if err != nil {
- return nil, err
- }
- items = append(items, *item)
- }
- if err := rows.Err(); err != nil {
- return nil, fmt.Errorf("iterate resource playfields: %w", err)
- }
- return items, nil
- }
- func (s *Store) GetResourcePlayfieldByPublicID(ctx context.Context, publicID string) (*ResourcePlayfield, error) {
- row := s.pool.QueryRow(ctx, `
- SELECT id, playfield_public_id, code, name, kind, status, description, current_version_id, created_at, updated_at
- FROM playfields
- WHERE playfield_public_id = $1
- LIMIT 1
- `, publicID)
- return scanResourcePlayfield(row)
- }
- func (s *Store) CreateResourcePlayfield(ctx context.Context, tx Tx, params CreateResourcePlayfieldParams) (*ResourcePlayfield, error) {
- row := tx.QueryRow(ctx, `
- INSERT INTO playfields (playfield_public_id, code, name, kind, status, description)
- VALUES ($1, $2, $3, $4, $5, $6)
- RETURNING id, playfield_public_id, code, name, kind, status, description, current_version_id, created_at, updated_at
- `, params.PublicID, params.Code, params.Name, params.Kind, params.Status, params.Description)
- return scanResourcePlayfield(row)
- }
- func (s *Store) ListResourcePlayfieldVersions(ctx context.Context, playfieldID string) ([]ResourcePlayfieldVersion, error) {
- rows, err := s.pool.Query(ctx, `
- SELECT id, version_public_id, playfield_id, version_code, status, source_type, source_url, published_asset_root,
- control_count, bounds_jsonb::text, metadata_jsonb::text, created_at, updated_at
- FROM playfield_versions
- WHERE playfield_id = $1
- ORDER BY created_at DESC
- `, playfieldID)
- if err != nil {
- return nil, fmt.Errorf("list resource playfield versions: %w", err)
- }
- defer rows.Close()
- items := []ResourcePlayfieldVersion{}
- for rows.Next() {
- item, err := scanResourcePlayfieldVersionFromRows(rows)
- if err != nil {
- return nil, err
- }
- items = append(items, *item)
- }
- if err := rows.Err(); err != nil {
- return nil, fmt.Errorf("iterate resource playfield versions: %w", err)
- }
- return items, nil
- }
- func (s *Store) GetResourcePlayfieldVersionByPublicID(ctx context.Context, playfieldPublicID, versionPublicID string) (*ResourcePlayfieldVersion, error) {
- row := s.pool.QueryRow(ctx, `
- SELECT pv.id, pv.version_public_id, pv.playfield_id, pv.version_code, pv.status, pv.source_type, pv.source_url, pv.published_asset_root,
- pv.control_count, pv.bounds_jsonb::text, pv.metadata_jsonb::text, pv.created_at, pv.updated_at
- FROM playfield_versions pv
- JOIN playfields p ON p.id = pv.playfield_id
- WHERE p.playfield_public_id = $1
- AND pv.version_public_id = $2
- LIMIT 1
- `, playfieldPublicID, versionPublicID)
- return scanResourcePlayfieldVersion(row)
- }
- func (s *Store) CreateResourcePlayfieldVersion(ctx context.Context, tx Tx, params CreateResourcePlayfieldVersionParams) (*ResourcePlayfieldVersion, error) {
- boundsJSON, err := marshalJSONMap(params.BoundsJSON)
- if err != nil {
- return nil, fmt.Errorf("marshal playfield bounds: %w", err)
- }
- metadataJSON, err := marshalJSONMap(params.MetadataJSON)
- if err != nil {
- return nil, fmt.Errorf("marshal playfield metadata: %w", err)
- }
- row := tx.QueryRow(ctx, `
- INSERT INTO playfield_versions (
- version_public_id, playfield_id, version_code, status, source_type, source_url,
- published_asset_root, control_count, bounds_jsonb, metadata_jsonb
- )
- VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9::jsonb, $10::jsonb)
- RETURNING id, version_public_id, playfield_id, version_code, status, source_type, source_url, published_asset_root,
- control_count, bounds_jsonb::text, metadata_jsonb::text, created_at, updated_at
- `, params.PublicID, params.PlayfieldID, params.VersionCode, params.Status, params.SourceType, params.SourceURL, params.PublishedAssetRoot, params.ControlCount, boundsJSON, metadataJSON)
- return scanResourcePlayfieldVersion(row)
- }
- func (s *Store) SetResourcePlayfieldCurrentVersion(ctx context.Context, tx Tx, playfieldID, versionID string) error {
- _, err := tx.Exec(ctx, `UPDATE playfields SET current_version_id = $2 WHERE id = $1`, playfieldID, versionID)
- if err != nil {
- return fmt.Errorf("set resource playfield current version: %w", err)
- }
- return nil
- }
- func (s *Store) ListResourcePacks(ctx context.Context, limit int) ([]ResourcePack, error) {
- if limit <= 0 || limit > 200 {
- limit = 50
- }
- rows, err := s.pool.Query(ctx, `
- SELECT id, resource_pack_public_id, code, name, status, description, current_version_id, created_at, updated_at
- FROM resource_packs
- ORDER BY created_at DESC
- LIMIT $1
- `, limit)
- if err != nil {
- return nil, fmt.Errorf("list resource packs: %w", err)
- }
- defer rows.Close()
- items := []ResourcePack{}
- for rows.Next() {
- item, err := scanResourcePackFromRows(rows)
- if err != nil {
- return nil, err
- }
- items = append(items, *item)
- }
- if err := rows.Err(); err != nil {
- return nil, fmt.Errorf("iterate resource packs: %w", err)
- }
- return items, nil
- }
- func (s *Store) GetResourcePackByPublicID(ctx context.Context, publicID string) (*ResourcePack, error) {
- row := s.pool.QueryRow(ctx, `
- SELECT id, resource_pack_public_id, code, name, status, description, current_version_id, created_at, updated_at
- FROM resource_packs
- WHERE resource_pack_public_id = $1
- LIMIT 1
- `, publicID)
- return scanResourcePack(row)
- }
- func (s *Store) CreateResourcePack(ctx context.Context, tx Tx, params CreateResourcePackParams) (*ResourcePack, error) {
- row := tx.QueryRow(ctx, `
- INSERT INTO resource_packs (resource_pack_public_id, code, name, status, description)
- VALUES ($1, $2, $3, $4, $5)
- RETURNING id, resource_pack_public_id, code, name, status, description, current_version_id, created_at, updated_at
- `, params.PublicID, params.Code, params.Name, params.Status, params.Description)
- return scanResourcePack(row)
- }
- func (s *Store) ListResourcePackVersions(ctx context.Context, resourcePackID string) ([]ResourcePackVersion, error) {
- rows, err := s.pool.Query(ctx, `
- SELECT id, version_public_id, resource_pack_id, version_code, status, content_entry_url, audio_root_url,
- theme_profile_code, published_asset_root, metadata_jsonb::text, created_at, updated_at
- FROM resource_pack_versions
- WHERE resource_pack_id = $1
- ORDER BY created_at DESC
- `, resourcePackID)
- if err != nil {
- return nil, fmt.Errorf("list resource pack versions: %w", err)
- }
- defer rows.Close()
- items := []ResourcePackVersion{}
- for rows.Next() {
- item, err := scanResourcePackVersionFromRows(rows)
- if err != nil {
- return nil, err
- }
- items = append(items, *item)
- }
- if err := rows.Err(); err != nil {
- return nil, fmt.Errorf("iterate resource pack versions: %w", err)
- }
- return items, nil
- }
- func (s *Store) GetResourcePackVersionByPublicID(ctx context.Context, resourcePackPublicID, versionPublicID string) (*ResourcePackVersion, error) {
- row := s.pool.QueryRow(ctx, `
- SELECT pv.id, pv.version_public_id, pv.resource_pack_id, pv.version_code, pv.status, pv.content_entry_url, pv.audio_root_url,
- pv.theme_profile_code, pv.published_asset_root, pv.metadata_jsonb::text, pv.created_at, pv.updated_at
- FROM resource_pack_versions pv
- JOIN resource_packs rp ON rp.id = pv.resource_pack_id
- WHERE rp.resource_pack_public_id = $1
- AND pv.version_public_id = $2
- LIMIT 1
- `, resourcePackPublicID, versionPublicID)
- return scanResourcePackVersion(row)
- }
- func (s *Store) CreateResourcePackVersion(ctx context.Context, tx Tx, params CreateResourcePackVersionParams) (*ResourcePackVersion, error) {
- metadataJSON, err := marshalJSONMap(params.MetadataJSON)
- if err != nil {
- return nil, fmt.Errorf("marshal resource pack metadata: %w", err)
- }
- row := tx.QueryRow(ctx, `
- INSERT INTO resource_pack_versions (
- version_public_id, resource_pack_id, version_code, status, content_entry_url,
- audio_root_url, theme_profile_code, published_asset_root, metadata_jsonb
- )
- VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9::jsonb)
- RETURNING id, version_public_id, resource_pack_id, version_code, status, content_entry_url, audio_root_url,
- theme_profile_code, published_asset_root, metadata_jsonb::text, created_at, updated_at
- `, params.PublicID, params.ResourcePackID, params.VersionCode, params.Status, params.ContentEntryURL, params.AudioRootURL, params.ThemeProfileCode, params.PublishedAssetRoot, metadataJSON)
- return scanResourcePackVersion(row)
- }
- func (s *Store) SetResourcePackCurrentVersion(ctx context.Context, tx Tx, resourcePackID, versionID string) error {
- _, err := tx.Exec(ctx, `UPDATE resource_packs SET current_version_id = $2 WHERE id = $1`, resourcePackID, versionID)
- if err != nil {
- return fmt.Errorf("set resource pack current version: %w", err)
- }
- return nil
- }
- func scanResourceMap(row pgx.Row) (*ResourceMap, error) {
- var item ResourceMap
- err := row.Scan(&item.ID, &item.PublicID, &item.Code, &item.Name, &item.Status, &item.Description, &item.CurrentVersionID, &item.CreatedAt, &item.UpdatedAt)
- if errors.Is(err, pgx.ErrNoRows) {
- return nil, nil
- }
- if err != nil {
- return nil, fmt.Errorf("scan resource map: %w", err)
- }
- return &item, nil
- }
- func scanResourceMapFromRows(rows pgx.Rows) (*ResourceMap, error) {
- var item ResourceMap
- err := rows.Scan(&item.ID, &item.PublicID, &item.Code, &item.Name, &item.Status, &item.Description, &item.CurrentVersionID, &item.CreatedAt, &item.UpdatedAt)
- if err != nil {
- return nil, fmt.Errorf("scan resource map row: %w", err)
- }
- return &item, nil
- }
- func scanResourceMapVersion(row pgx.Row) (*ResourceMapVersion, error) {
- var item ResourceMapVersion
- var boundsJSON string
- var metadataJSON string
- err := row.Scan(&item.ID, &item.PublicID, &item.MapID, &item.VersionCode, &item.Status, &item.MapmetaURL, &item.TilesRootURL, &item.PublishedAssetRoot, &boundsJSON, &metadataJSON, &item.CreatedAt, &item.UpdatedAt)
- if errors.Is(err, pgx.ErrNoRows) {
- return nil, nil
- }
- if err != nil {
- return nil, fmt.Errorf("scan resource map version: %w", err)
- }
- item.BoundsJSON = json.RawMessage(boundsJSON)
- item.MetadataJSON = json.RawMessage(metadataJSON)
- return &item, nil
- }
- func scanResourceMapVersionFromRows(rows pgx.Rows) (*ResourceMapVersion, error) {
- var item ResourceMapVersion
- var boundsJSON string
- var metadataJSON string
- err := rows.Scan(&item.ID, &item.PublicID, &item.MapID, &item.VersionCode, &item.Status, &item.MapmetaURL, &item.TilesRootURL, &item.PublishedAssetRoot, &boundsJSON, &metadataJSON, &item.CreatedAt, &item.UpdatedAt)
- if err != nil {
- return nil, fmt.Errorf("scan resource map version row: %w", err)
- }
- item.BoundsJSON = json.RawMessage(boundsJSON)
- item.MetadataJSON = json.RawMessage(metadataJSON)
- return &item, nil
- }
- func scanResourcePlayfield(row pgx.Row) (*ResourcePlayfield, error) {
- var item ResourcePlayfield
- err := row.Scan(&item.ID, &item.PublicID, &item.Code, &item.Name, &item.Kind, &item.Status, &item.Description, &item.CurrentVersionID, &item.CreatedAt, &item.UpdatedAt)
- if errors.Is(err, pgx.ErrNoRows) {
- return nil, nil
- }
- if err != nil {
- return nil, fmt.Errorf("scan resource playfield: %w", err)
- }
- return &item, nil
- }
- func scanResourcePlayfieldFromRows(rows pgx.Rows) (*ResourcePlayfield, error) {
- var item ResourcePlayfield
- err := rows.Scan(&item.ID, &item.PublicID, &item.Code, &item.Name, &item.Kind, &item.Status, &item.Description, &item.CurrentVersionID, &item.CreatedAt, &item.UpdatedAt)
- if err != nil {
- return nil, fmt.Errorf("scan resource playfield row: %w", err)
- }
- return &item, nil
- }
- func scanResourcePlayfieldVersion(row pgx.Row) (*ResourcePlayfieldVersion, error) {
- var item ResourcePlayfieldVersion
- var boundsJSON string
- var metadataJSON string
- err := row.Scan(&item.ID, &item.PublicID, &item.PlayfieldID, &item.VersionCode, &item.Status, &item.SourceType, &item.SourceURL, &item.PublishedAssetRoot, &item.ControlCount, &boundsJSON, &metadataJSON, &item.CreatedAt, &item.UpdatedAt)
- if errors.Is(err, pgx.ErrNoRows) {
- return nil, nil
- }
- if err != nil {
- return nil, fmt.Errorf("scan resource playfield version: %w", err)
- }
- item.BoundsJSON = json.RawMessage(boundsJSON)
- item.MetadataJSON = json.RawMessage(metadataJSON)
- return &item, nil
- }
- func scanResourcePlayfieldVersionFromRows(rows pgx.Rows) (*ResourcePlayfieldVersion, error) {
- var item ResourcePlayfieldVersion
- var boundsJSON string
- var metadataJSON string
- err := rows.Scan(&item.ID, &item.PublicID, &item.PlayfieldID, &item.VersionCode, &item.Status, &item.SourceType, &item.SourceURL, &item.PublishedAssetRoot, &item.ControlCount, &boundsJSON, &metadataJSON, &item.CreatedAt, &item.UpdatedAt)
- if err != nil {
- return nil, fmt.Errorf("scan resource playfield version row: %w", err)
- }
- item.BoundsJSON = json.RawMessage(boundsJSON)
- item.MetadataJSON = json.RawMessage(metadataJSON)
- return &item, nil
- }
- func scanResourcePack(row pgx.Row) (*ResourcePack, error) {
- var item ResourcePack
- err := row.Scan(&item.ID, &item.PublicID, &item.Code, &item.Name, &item.Status, &item.Description, &item.CurrentVersionID, &item.CreatedAt, &item.UpdatedAt)
- if errors.Is(err, pgx.ErrNoRows) {
- return nil, nil
- }
- if err != nil {
- return nil, fmt.Errorf("scan resource pack: %w", err)
- }
- return &item, nil
- }
- func scanResourcePackFromRows(rows pgx.Rows) (*ResourcePack, error) {
- var item ResourcePack
- err := rows.Scan(&item.ID, &item.PublicID, &item.Code, &item.Name, &item.Status, &item.Description, &item.CurrentVersionID, &item.CreatedAt, &item.UpdatedAt)
- if err != nil {
- return nil, fmt.Errorf("scan resource pack row: %w", err)
- }
- return &item, nil
- }
- func scanResourcePackVersion(row pgx.Row) (*ResourcePackVersion, error) {
- var item ResourcePackVersion
- var metadataJSON string
- err := row.Scan(&item.ID, &item.PublicID, &item.ResourcePackID, &item.VersionCode, &item.Status, &item.ContentEntryURL, &item.AudioRootURL, &item.ThemeProfileCode, &item.PublishedAssetRoot, &metadataJSON, &item.CreatedAt, &item.UpdatedAt)
- if errors.Is(err, pgx.ErrNoRows) {
- return nil, nil
- }
- if err != nil {
- return nil, fmt.Errorf("scan resource pack version: %w", err)
- }
- item.MetadataJSON = json.RawMessage(metadataJSON)
- return &item, nil
- }
- func scanResourcePackVersionFromRows(rows pgx.Rows) (*ResourcePackVersion, error) {
- var item ResourcePackVersion
- var metadataJSON string
- err := rows.Scan(&item.ID, &item.PublicID, &item.ResourcePackID, &item.VersionCode, &item.Status, &item.ContentEntryURL, &item.AudioRootURL, &item.ThemeProfileCode, &item.PublishedAssetRoot, &metadataJSON, &item.CreatedAt, &item.UpdatedAt)
- if err != nil {
- return nil, fmt.Errorf("scan resource pack version row: %w", err)
- }
- item.MetadataJSON = json.RawMessage(metadataJSON)
- return &item, nil
- }
- func marshalJSONMap(value map[string]any) (string, error) {
- if value == nil {
- value = map[string]any{}
- }
- raw, err := json.Marshal(value)
- if err != nil {
- return "", err
- }
- return string(raw), nil
- }
|