A vibe coded tangled fork which supports pijul.
at sl/tap-appview 134 lines 2.5 kB view raw
1package db 2 3import ( 4 "fmt" 5 "strings" 6 "time" 7 8 "github.com/go-git/go-git/v5/plumbing" 9 "github.com/ipfs/go-cid" 10 "tangled.org/core/appview/models" 11 "tangled.org/core/orm" 12) 13 14func UpsertArtifact(e Execer, artifact models.Artifact) error { 15 panic("unimplemented") 16} 17 18func AddArtifact(e Execer, artifact models.Artifact) error { 19 _, err := e.Exec( 20 `insert or ignore into artifacts ( 21 did, 22 rkey, 23 repo_at, 24 tag, 25 created, 26 blob_cid, 27 name, 28 size, 29 mimetype 30 ) 31 values (?, ?, ?, ?, ?, ?, ?, ?, ?)`, 32 artifact.Did, 33 artifact.Rkey, 34 artifact.RepoAt, 35 artifact.Tag[:], 36 artifact.CreatedAt.Format(time.RFC3339), 37 artifact.BlobCid.String(), 38 artifact.Name, 39 artifact.Size, 40 artifact.MimeType, 41 ) 42 return err 43} 44 45func GetArtifact(e Execer, filters ...orm.Filter) ([]models.Artifact, error) { 46 var artifacts []models.Artifact 47 48 var conditions []string 49 var args []any 50 for _, filter := range filters { 51 conditions = append(conditions, filter.Condition()) 52 args = append(args, filter.Arg()...) 53 } 54 55 whereClause := "" 56 if conditions != nil { 57 whereClause = " where " + strings.Join(conditions, " and ") 58 } 59 60 query := fmt.Sprintf(`select 61 did, 62 rkey, 63 repo_at, 64 tag, 65 created, 66 blob_cid, 67 name, 68 size, 69 mimetype 70 from artifacts %s`, 71 whereClause, 72 ) 73 74 rows, err := e.Query(query, args...) 75 if err != nil { 76 return nil, err 77 } 78 defer rows.Close() 79 80 for rows.Next() { 81 var artifact models.Artifact 82 var createdAt string 83 var tag []byte 84 var blobCid string 85 86 if err := rows.Scan( 87 &artifact.Did, 88 &artifact.Rkey, 89 &artifact.RepoAt, 90 &tag, 91 &createdAt, 92 &blobCid, 93 &artifact.Name, 94 &artifact.Size, 95 &artifact.MimeType, 96 ); err != nil { 97 return nil, err 98 } 99 100 artifact.CreatedAt, err = time.Parse(time.RFC3339, createdAt) 101 if err != nil { 102 artifact.CreatedAt = time.Now() 103 } 104 artifact.Tag = plumbing.Hash(tag) 105 artifact.BlobCid = cid.MustParse(blobCid) 106 107 artifacts = append(artifacts, artifact) 108 } 109 110 if err := rows.Err(); err != nil { 111 return nil, err 112 } 113 114 return artifacts, nil 115} 116 117func DeleteArtifact(e Execer, filters ...orm.Filter) error { 118 var conditions []string 119 var args []any 120 for _, filter := range filters { 121 conditions = append(conditions, filter.Condition()) 122 args = append(args, filter.Arg()...) 123 } 124 125 whereClause := "" 126 if conditions != nil { 127 whereClause = " where " + strings.Join(conditions, " and ") 128 } 129 130 query := fmt.Sprintf(`delete from artifacts %s`, whereClause) 131 132 _, err := e.Exec(query, args...) 133 return err 134}