๐พ Archived View for source.community โบ Fuwn โบ space โบ blob โบ main โบ pkg โบ database โบ database.go captured on 2024-02-05 at 10:01:57. Gemini links have been rewritten to link to archived content
โฌ ๏ธ Previous capture (2023-07-10)
-=-=-=-=-=-=-
. ,-. ,-. . . ,-. ,-. ,-. ,-. ,-. ,-,-. ,-,-. . . ,-. . |- . . `-. | | | | | | |-' | | | | | | | | | | | | | | | | | `-' `-' `-^ ' `-' `-' :: `-' `-' ' ' ' ' ' ' `-^ ' ' ' `' `-| /| `-'
git clone https://source.community/Fuwn/space.git
View raw contents of /pkg/database/database.go (main)
โโโโโฎ 1โ // Copyright (C) 2021-2021 Fuwn 2โ // SPDX-License-Identifier: GPL-3.0-only 3โ 4โ package database 5โ 6โ import ( 7โ "github.com/sonyarouje/simdb" 8โ ) 9โ 10โ var driver *simdb.Driver 11โ 12โ func init() { 13โ var err error 14โ driver, err = simdb.New(".space/database") 15โ if err != nil { 16โ panic(err) 17โ } 18โ } 19โ 20โ type Hit struct { 21โ Path string `json:"path"` 22โ Count int `json:"count"` 23โ } 24โ 25โ func (c Hit) ID() (jsonField string, value interface{}) { 26โ value = c.Path 27โ jsonField = "path" 28โ return 29โ } 30โ 31โ func Get(path string) int { 32โ var hit Hit 33โ 34โ err := driver.Open(Hit{}).Where("path", "=", path).First().AsEntity(&hit) 35โ if err != nil { 36โ return 0 37โ } 38โ 39โ return hit.Count + 1 40โ } 41โ 42โ func Create(path string) { 43โ driver.Insert(Hit{ 44โ Path: path, 45โ Count: 0, 46โ }) 47โ } 48โ 49โ func Increment(path string) { 50โ var hit Hit 51โ 52โ err := driver.Open(Hit{}).Where("path", "=", path).First().AsEntity(&hit) 53โ if err != nil { 54โ return 55โ } 56โ 57โ hit.Count = hit.Count + 1 58โ driver.Update(hit) 59โ } โโโโโฏ
ยท ยท ยท
ยฉ 2024 source.community