smart_arrays_dbstore 2.1.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 62

Smart Arrays Database Store #

What the package can do for you #

  • This package was designed for Web applications which need to store data on the local device (PC, tablet, phone) over a longer time period, e.g. to view or process the data by a Web app during multiple sessions.

  • The package is capable of saving one- and two-dimensional arrays of double values and String-valued maps in databases, optionally along with metadata containing additional information about the actual array data.

  • Arrays with their metadata are considered as "datasets" of type DSet. A DSet can be created from arrays and metadata using this package.

  • Each dataset DSet is stored in its own database of type IndexedDB under the browser. The user must define its name (similar as one would do it under a file system) for later retrieval.

  • Many datasets, even of big size (e.g. array sizes of several megabytes) may be stored. The exact limits per origin are browser dependent. Browsers derive their limits from the available storage using their own algorithms.

  • The package was tested using the following browsers: Chrome under Windows, Linux, Android, iOS. Safari under iOS.

  • Datset sets will remain stored until

    • they are explicitely deleted by using respective API functions provided by this package.
    • the user deleted the browser data via respective functions of the operating system or from the browser's advanced settings menu.
    • the browser itself decided to delete data. This may happen if storage on the local machine is running tight ("storage pressure"). However: Some browsers (e.g. Chrome) support "persistent" data. This package provides a function 'DSetDB.persistent' requesting data to make the storage persistent ("durable") if supported. You must check with your browser whether and under which conditions persistence is granted. For Chrome you may e.g. check the site https://developers.google.com/web/fundamentals/instant-and-offline/web-storage/offline-for-pwa.
  • This packages utilizes IndexedDB databases managed by the browser. Their technical storage method and storage location on a device is browser dependent, and also depends on the origin from which the Web app is served. For Chrome, you can list the databases by entering chrome://indexeddb-internals into the browser's address field.

The major API functionalities #

  • Class DSet to create a datset from arrays and its metadata:

  • Class DSkey to create a datset key (dataset identifier) under which a dataset will be stored.

  • Class DSetStore, a handler to store datasets on the device, to load stored datasets, to delete, copy, rename datasets, to obtain a list (directory) of stored datasets, to save information common to all datasets in a global store, to classify datasets into projects.

  • Class DSetDB to initially create a DSetStore required to apply the functionalities above.

  • Basic usage to store a datset:

    • create a dataset of type DSet from your array and metadata (constructor DSet).
    • create a DSkey identifier for your data in the store (method DSKey.create)
    • create a DSetStore storage handler (method DSetDB.createDSetStore).
    • invoke DSetStore.dsSave to store the data
  • Basic usage to load a stored datset:

    • create a DSkey identifier for the data you want to load from the store (method DSKey.create)
    • create a DSetStore storage handler (method DSetDB.createDSetStore).
    • invoke DSetStore.dsLoad to load stored data
  • Basic usage to find out which datasets are available in the store:

    • create a DSetStore storage handler (method DSetDB.createDSetStore).
    • invoke DSetStore.projectsGet to get a list of all projects.
    • For each project, invoke DSetStore.dskeysWithProject to get a list of the dataset keys of the dataset stored under this project. You will use then such a key to load the data. Or you can build a GUI displaying the projects with their datasets.

Please check the provided example for details.

smart_arrays_base: Basic functions for 1D and 2D arrays

smart_arrays_numerics: Numerics with 1D and 2D arrays

smart_arrays_compress: Compress 1D and 2D arrays to a smaller size.

smart_arrays_sample_data: Computes 1D and 2D arrays containing sample data.

smart_arrays_dbstore: Store 1D and 2D arrays along with metadata on the local device.

smart_arrays_peaks: Detect peaks in 1D and 2D arrays.

smart_arrays_contour_finder: Contours the three-dimensional surface represented by the values f(x,y) of a matrix.

smart_arrays_plot_polyline: Plot 1D arrays as polyline along with axes and more.

smart_arrays_lmfit: Fits (x, y) data given as arrays to a specified model function using the Levenberg-Marquardt algorithm.

smart_lorentz_gauss: Compute Lorentz-Gauss (pseudo-Voigt) line shapes.

smart_signal_processing: Fourier transform and more of arrays.

smart_dialogs: Easy-to-use dialogs in Web applications

Smart Arrays Database Store #

Version history #

2.1.0 - 2019-10-05 now sdk 2.5.0 in pubspec

2.0.0 - 2019-04-28 First version available on pub.dev.

2.0.1 - 2019-05-28 Rename "UJson" to "UtilsJson".

2.0.2 - 2019-05-28 Rename Added method to request persistent storage.

2.0.3 - Docu updates

2.0.4 - 2019-08-04 Fixed health suggestions of pub.dev

2.0.5 - 2019-08-04 Using package:pedantic/analysis_options.yaml from now on

2.0.6 - pubspec description update

example/example.dart

import 'dart:typed_data';
import 'package:smart_arrays_dbstore/smart_arrays_dbstore.dart';

// This example demonstrates the basic use of the smart_arrays_dbstore package:
// A vector and a matrix will be stored in a database. Then the stored data will
// be loaded from the database and printed.
main() async {
  // define the base name for all databases where the datasets of this example
  // get stored. The individual db name for each dataset is constructed
  // automatically by appending a unique number to the base name.
  // Also define the name of the db containing common ("global") information
  // about the datasets.
  const DS_DB_NAME_BASE = "testdb.", DS_DB_NAME_GLOB = "testdb_glob";

  // create a dataset storage handler
  DSetStore dsStore =
      await DSetDB.createDSetStore(DS_DB_NAME_BASE, DS_DB_NAME_GLOB);
  if (dsStore == null) {
    printError();
    return;
  }

  // in the following code, we store a vector and a matrix along with metadata
  VECTOR_METADATA["Storage Date"] = DateTime.now().toIso8601String();

  // create a dataset from VECTOR, its "imaginary" part, and its metadata
  DSet ds1 = DSet(VECTOR, VECTOR_IMAG, VECTOR_METADATA);

  // Create a key under which [ds1] gets stored in the database.
  // The first argument is the actual dataset name, the 2nd allows one to put
  // datasets into the same or different categories ("projects"), and the 3rd
  // one is an arbitrary indicator for the type of data.
  DSKey dskey1 = DSKey("vector-1", "project-1", "spectrum-1D");
  await dsStore.dsSave(dskey1, ds1); // store [ds1] under [dskey1]

  MATRIX_METADATA["Storage Date"] = DateTime.now().toIso8601String();

  // create a dataset from MATRIX and its metadata, no "imaginary" data present
  DSet ds2 = DSet.twoD(MATRIX, null, MATRIX_METADATA);

  // Create a key under which [ds2] gets stored in the database.
  // We store it under the category "project-2".
  DSKey dskey2 = DSKey("matrix-1", "project-2", "spectrum-2D");
  await dsStore.dsSave(dskey2, ds2); // store [ds2] under [dskey2]

  // save a a property common to [ds1] and [ds2] in the global database
  await dsStore.gpropSave(
      "Comment", "These are the stored data of 'example.dart:'");

  // now we load the data stored above and print the result.
  // create dataset storage handler for our databases
  dsStore = await DSetDB.createDSetStore(DS_DB_NAME_BASE, DS_DB_NAME_GLOB);

  print("Comment=${dsStore.gpropGet("Comment")}");
  print("Projects defined=${dsStore.projectsGet().keys}");

  // now load and print the datasets with their metadata
  ds1 = await dsStore.dsLoad(dskey1);
  print("Loaded vector=${ds1.values}");
  print("The vector's metadata=${ds1.meta}");
  print("Imag=${(await dsStore.dscompLoad(dskey1, DSetStore.DSC_IMAG))[0]}");

  ds2 = await dsStore.dsLoad(dskey2);
  print("Loaded matrix=${ds2.values2D}");
  print("The matrix's metadata=${ds2.meta}");
}

final Float64List VECTOR =
    Float64List.fromList([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
final Float64List VECTOR_IMAG =
    Float64List.fromList([-1, -2, -3, -4, -5, -6, -7, -8, -9, -10]);

Map<String, String> VECTOR_METADATA = {
  "TITLE": "VECTOR metadata",
  "ORIGIN": "Example app.",
  "Array size": "${VECTOR.length}",
};

final List<Float64List> MATRIX = [
  Float64List.fromList([1, 1, 1, 0]),
  Float64List.fromList([0, 3, 1, 2]),
  Float64List.fromList([2, 3, 1, 0]),
  Float64List.fromList([1, 0, 2, 1])
];

Map<String, String> MATRIX_METADATA = {
  "TITLE": "MATRIX metadata",
  "ORIGIN": "Example app.",
  "Number of rows": "${MATRIX.length}",
  "Number of columns": "${MATRIX[0].length}"
};

printError() {
  print("Can't open or create an 'indexeddb' database");
  print("If creation failure: perhaps browser doesn't support 'IndexedDB'.");
  print("Note: Chrome on all platforms and Safari iOS do support it.");
  print("If open failure: probably database doesn't exist.");
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  smart_arrays_dbstore: ^2.1.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:smart_arrays_dbstore/smart_arrays_dbstore.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
24
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
62
Learn more about scoring.

We analyzed this package on Nov 20, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.6.1
  • pana: 0.12.21

Platforms

Detected platforms: web

Primary library: package:smart_arrays_dbstore/smart_arrays_dbstore.dart with components: html.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.5.0 <3.0.0
build_runner ^1.6.2 1.7.2
build_web_compilers ^2.1.4 2.7.1
pedantic ^1.7.0 1.8.0+1
smart_arrays_base ^2.0.6 2.1.0
Transitive dependencies
_fe_analyzer_shared 1.0.0
analyzer 0.39.1
archive 2.0.11
args 1.5.2
async 2.4.0
bazel_worker 0.1.23
build 1.2.2
build_config 0.4.1+1
build_daemon 2.1.2
build_modules 2.7.0
build_resolvers 1.3.0
build_runner_core 4.2.0
built_collection 4.3.0
built_value 7.0.0
charcode 1.1.2
checked_yaml 1.0.2
code_builder 3.2.1
collection 1.14.12
convert 2.1.1
crypto 2.1.3
csslib 0.16.1
dart_style 1.3.3
fixnum 0.10.11
front_end 0.1.29
glob 1.2.0
graphs 0.2.0
html 0.14.0+3
http 0.12.0+2
http_multi_server 2.1.0
http_parser 3.1.3
io 0.3.3
js 0.6.1+1
json_annotation 3.0.0
kernel 0.3.29
logging 0.11.3+2
matcher 0.12.6
meta 1.1.8
mime 0.9.6+3
node_interop 1.0.3
node_io 1.0.1+2
package_config 1.1.0
package_resolver 1.0.10
path 1.6.4
pool 1.4.0
protobuf 1.0.1
pub_semver 1.4.2
pubspec_parse 0.1.5
quiver 2.1.2+1
scratch_space 0.0.4+1
shelf 0.7.5
shelf_web_socket 0.2.3
source_maps 0.10.8
source_span 1.5.5
stack_trace 1.9.3
stream_channel 2.0.0
stream_transform 0.0.20
string_scanner 1.0.5
term_glyph 1.1.0
timing 0.1.1+2
typed_data 1.1.6
watcher 0.9.7+12
web_socket_channel 1.1.0
yaml 2.2.0