kvstore

package
v3.0.0-alpha.9 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2024 License: MIT Imports: 5 Imported by: 0

README

KVStore Plugin

This plugin provides a simple key/value store for your Wails applications.

Installation

Add the plugin to the Plugins option in the Applications options:

package main

import (
	"github.com/zappie/wails/v3/pkg/application"
	"github.com/zappie/wails/v3/plugins/kvstore"
)

func main() {
	kvstorePlugin := kvstore.NewPlugin(&kvstore.Config{
		Filename: "myapp.db",
	})
	app := application.New(application.Options{
		// ...
		Plugins: map[string]application.Plugin{
			"kvstore": kvstorePlugin,
		},
	})

Usage

Go

You can call the methods exported by the plugin directly:

    err := kvstore.Set("url", "https://www.google.com")
    if err != nil {
        // handle error
    }
    url := kvstore.Get("url").(string)
    
	// If you have not enables AutoSave, you will need to call Save() to persist the changes
    err = kvstore.Save()
    if err != nil {
        // handle error
    }
Javascript

You can call the methods from the frontend using the Plugin method:

    wails.Plugin("kvstore","Set", "url", "https://www.google.com")
    wails.Plugin("kvstore","Get", "url").then((url) => {
        
    })
    
    // or
    wails.Plugin("browser","OpenFile","/path/to/file")

Support

If you find a bug in this plugin, please raise a ticket on the Wails Issue Tracker.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Filename string
	AutoSave bool
}

type KeyValueStore

type KeyValueStore struct {
	// contains filtered or unexported fields
}

func NewPlugin

func NewPlugin(config *Config) *KeyValueStore

func (*KeyValueStore) CallableByJS

func (kvs *KeyValueStore) CallableByJS() []string

func (*KeyValueStore) Get

func (kvs *KeyValueStore) Get(key string) any

Get returns the value for the given key. If key is empty, the entire store is returned.

func (*KeyValueStore) Init

func (kvs *KeyValueStore) Init() error

Init is called when the plugin is loaded. It is passed the application.App instance. This is where you should do any setup.

func (*KeyValueStore) InjectJS

func (kvs *KeyValueStore) InjectJS() string

func (*KeyValueStore) Name

func (kvs *KeyValueStore) Name() string

Name returns the name of the plugin.

func (*KeyValueStore) Save

func (kvs *KeyValueStore) Save() error

Save saves the store to disk

func (*KeyValueStore) Set

func (kvs *KeyValueStore) Set(key string, value any) error

Set sets the value for the given key. If AutoSave is true, the store is saved to disk.

func (*KeyValueStore) Shutdown

func (kvs *KeyValueStore) Shutdown()

Shutdown will save the store to disk if there are unsaved changes.

type Plugin

type Plugin struct{}

func (*Plugin) InjectJS

func (p *Plugin) InjectJS() string

Jump to

Keyboard shortcuts

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