cacheDatabase

package module
v0.0.0-...-e0bd58e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 16, 2023 License: MIT Imports: 11 Imported by: 0

README

# Cache SQL

The cacheSQL library is an algorithm used in my backup software (in 2012). The goal was to improve SQL writing in sqlite on simple objects in view of making file paths in SQL databases.
The new lib is updated with use of gorm and more generic use.

It is therefore still experiential and I only use it in rare performance cases.

Becarefull: Any data that is not recorded via the lib or complex query usage is not cached.

The library records data every second. If the recorded data causes an error, you are not informed.

## Use General
Informs the index cache to be created by ListKeyUnique
```

type SchoolSimply struct {
	ID   uint `gorm:"primarykey"`
	Name string
}  

func (school SchoolSimply) ListKeyUnique() []string {
	return []string{"ID", "Name"}
}

```

Get data into cache
```bash
databaseGetWithCache(&s4, "ParentID", fmt.Sprintf("%v", s21.ID))
```

Save data into cache
```bash
SaveData(&s)
```

## Use with Path
### Init 
```
type TestFile struct {
	FileTemplate
	Mode uint
	Size uint64
	Uid int
	Gid int
}
```
### Get Path
```bash
_, err = GetPath(&TestFile{}, "/tmp/dataCache/Welcome")


### Save Path
```bash
_, err = GetPath(&TestFile{}, "/tmp/dataCache/Welcome")
```


## Example USE
### cmd_folder_scan
cmd_folder_scan which calculates the size in each folder.
The program has a problem in propagating sizes up to the root.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// SEPARATOR_FIELDS filedName/value into string transformation cache
	SEPARATOR_FIELDS string = "||"

	// ErrRecordNotFound record not found error
	ErrRecordNotFound = gorm.ErrRecordNotFound

	// ErrRecordNotFound stucture not found error
	ErrStructureNotFound = fmt.Errorf("Impossible trouver la structure")

	// ErrErrNotPointer
	ErrErrNotPointer = fmt.Errorf("LA structure n'est pas un pointer")
)
View Source
var DB *gorm.DB
View Source
var DEBUG bool
View Source
var ErrRecordExistCache error = fmt.Errorf("Record Exist into cache")

Functions

func CommitData

func CommitData()

func CreatePath

func CreatePath(objectInterfaceStructPtr interface{}, path string) (interface{}, error)

Create Path into cache

func DisplayCache

func DisplayCache(cache cacheSQL)

func GetCache

func GetCache(object interface{}, fieldIndexName string, values ...string) (interface{}, error)

GetCache recupere une donnée de type object et retourne le resultat

func GetPath

func GetPath(pathInterfaceStructPtr interface{}, path string) (interface{}, error)

GetPath: function return object Ptr From pathInterfaceStructPtr Type with the path

func InsertCache

func InsertCache(object interface{}) error

func SaveData

func SaveData(data interface{}) error

saveData: Save data and insert into cache

func SavePath

func SavePath(pathInterfaceStructPtr interface{}) (pathInterfaceStructPtrInCache interface{}, err error)

SavePath: Save data

Types

type FileTemplate

type FileTemplate struct {
	ID       uint   `gorm:"primarykey"`
	ParentID uint   `gorm:"index:idx_parentid_name,unique"`
	Name     string `gorm:"index:idx_parentid_name,unique"`

	// Path: Indicatif
	Path string `gorm:"-"`
	// contains filtered or unexported fields
}

func (*FileTemplate) GetPathParent

func (fileTemplate *FileTemplate) GetPathParent() (pathParent string)

GetParent

func (FileTemplate) ListKeyUnique

func (fileTemplate FileTemplate) ListKeyUnique() []string

ListKeyUnique: List index into cache memory

func (*FileTemplate) PreSave

func (fileTemplate *FileTemplate) PreSave(db *gorm.DB, objectPtr interface{}) error

PreSave: function call just before save into routine with transaction

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL