๐Ÿ’พ 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

View Raw

More Information

โฌ…๏ธ Previous capture (2023-07-10)

๐Ÿšง View Differences

-=-=-=-=-=-=-

                                                         .
,-. ,-. . . ,-. ,-. ,-.    ,-. ,-. ,-,-. ,-,-. . . ,-. . |- . .
`-. | | | | |   |   |-'    |   | | | | | | | | | | | | | |  | |
`-' `-' `-^ '   `-' `-' :: `-' `-' ' ' ' ' ' ' `-^ ' ' ' `' `-|
                                                             /|
                                                            `-'

Profile for Fuwn

Fuwn / space

git clone https://source.community/Fuwn/space.git

Branches

Log

Tree

/pkg/database/database.go (main)

โ†‘ /pkg/database

blob

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โ”‚ }
โ”€โ”€โ”€โ”€โ•ฏ

ยท ยท ยท

๐Ÿก Home

FAQs

Privacy Policy

Terms & Conditions

Official Gemlog

info@source.community

ยฉ 2024 source.community