Skip to content

zepp-health/easy-storage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📦 Easy Storage Library for ZeppOS

Description

The EasyStorage suite is a handy set of tools for ZeppOS applications. It includes EasyStorage, EasyFlashStorage, and EasyTempStorage. These tools give developers a wide range of options for managing data, from storing it in memory or in files, to using temporary storage. Each tool is designed to meet specific storage needs, making it easier and more efficient to handle application data. Next to these the suite has a Storage utility library that offers static methods for direct file operations. This includes reading and writing JSON objects, text, and binary data directly to and from the filesystem.

Alongside these storage solutions, we have EasyTSDB (time-series database). It’s a special part of the EasyStorage suite that’s all about managing time-series data. Just like InfluxDB, EasyTSDB is great at storing, retrieving, and analyzing time-series data. It uses a mix of RAM and filesystem storage to manage data effectively, and can handle data flushes to disk when RAM gets full. It’s perfect for applications that need to manage time-series data effectively, and it supports custom aggregation and querying over specific time ranges.

Installation

To install the library, run the following command from the root of your project:

npm i @silver-zepp/easy-storage

✨️ Examples

➡️ 1. Using EasyStorage for Persistent Storage [Read API🔗]

A lightweight, hybrid storage solution combining in-memory efficiency with filesystem persistence, ideal for small to medium-sized data.

import EasyStorage from "@silver-zepp/easy-storage";
const storage = new EasyStorage();

storage.setKey("name", "John Doe");
console.log(storage.getKey("user")); // "John Doe"

➡️ 2. Analyzing Time-Series Data with EasyTSDB [Read API🔗]

Efficiently manage and analyze time-series data, supporting a wide array of aggregation functions for comprehensive data analysis, making it perfect for applications requiring detailed time-based insights.

import { EasyTSDB } from "@silver-zepp/easy-storage";
const db = new EasyTSDB();

// write some data points
db.writePoint('temperature', 22.5); // if not provided -> use the current timestamp
db.writePoint('humidity', 55, Date.now() - 60 * 60 * 1000); // 1 hour ago

// query the average temperature over the last 2 hours
const start_time = Date.now() - 2 * 60 * 60 * 1000; // 2 hours ago
const end_time = Date.now();
const avg_temp = db.query(start_time, end_time, 'average');

console.log(`Average temperature over the last 2 hours: ${avg_temp}`);

➡️ 3. Using EasyFlashStorage for Large, Persistent Storage [Read API🔗]

Designed for heavy-duty storage needs, it leverages filesystem-based persistence to handle large datasets without compromising performance and saving RAM.

import { EasyFlashStorage } from "@silver-zepp/easy-storage";
const flash = new EasyFlashStorage();

flash.setKey("config", { theme: "dark", notifications: true, ... });
console.log(flash.getKey("config"));

➡️ 4. Using EasyTempStorage for Temporary, Volatile Storage [Read API🔗]

Offers a transient, in-memory storage space for temporary data, ensuring fast access speeds and automatic clearance upon application closure.

import { EasyTempStorage } from "@silver-zepp/easy-storage";
const temp = new EasyTempStorage();

temp.setKey("session", { token: "abc123" });
console.log(temp.getKey("session"));

➡️ 5. Direct File Operations with Storage Utility [Read API🔗]

A utility library providing straightforward, static methods for direct file operations, simplifying reading and writing of data to the filesystem.

import { Storage } from "@silver-zepp/easy-storage";

Storage.WriteFile("log.txt", "log entry example");
console.log(Storage.ReadFile("log.txt"));

📝 EasyStorage API Reference

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published