/shadertoy_moor

Primary LanguageDartMIT LicenseMIT

shadertoy_moor

A Shadertoy API storage implementation with moor

Pub Package Build Status Coverage Status Package Documentation GitHub License

Introduction

This package implements the storage APIs defined in the shadertoy_api package providing a moor backed implementation

Capabilities

The following methods are implemented:

  • Find all user ids
  • Save user
  • Save users
  • Delete user by id
  • Save shader
  • Save shaders
  • Delete shader by id
  • Save shader comments
  • Save playlist
  • Save playlist shaders
  • Delete playlist by id

Getting Started

Add this to your pubspec.yaml (or create it):

dependencies:
    shadertoy_moor: ^1.0.5

Run the following command to install dependencies:

pub get

Finally, to start developing import the library:

import 'package:shadertoy_moor/shadertoy_moor.dart';

Usage

To create a new store the ShadertoyStore implementation needs to be instanciated. The example bellow creates a new moor store with an in memory implementation (mostly used for test purposes)

import 'package:moor/ffi.dart';
import 'package:moor/moor.dart';
import 'package:shadertoy_moor/shadertoy_moor.dart';

QueryExecutor memoryExecutor({bool logStatements = false}) {
  return VmDatabase.memory(logStatements: logStatements);
}

final store = newShadertoyMoorStore(memoryExecutor())

A more real example would entail de creation of a database backed by a file like so:

import 'dart:io';

import 'package:moor/ffi.dart';
import 'package:moor/moor.dart';
import 'package:shadertoy_api/shadertoy_api.dart';
import 'package:shadertoy_moor/shadertoy_moor.dart';

QueryExecutor diskExecutor(File file, {bool logStatements = false}) {
  return VmDatabase(file, logStatements: logStatements);
}

final store = newShadertoyMoorStore(diskExecutor(File('shadertoy.db')))

This allows the execution of persistent operations, for example storing the definition of a shader with:

final shader = Shader(...);
final ssr = await store.saveShader(shader);
if (ssr.ok) {
    print('Shader stored');
} else {
    print('Error: ${response.error.message}')
}

Model

Shadertoy Storage Model

Contributing

This a unofficial Shadertoy storage library. It is developed by best effort, in the motto of "Scratch your own itch!", meaning APIs that are meaningful for the author use cases.

If you would like to contribute with other parts of the API, feel free to make a Github pull request as I'm always looking for contributions for:

  • Tests
  • Documentation
  • New APIs

Features and Bugs

Please file feature requests and bugs at the issue tracker.

License

This project is licensed under the MIT License - see the LICENSE file for details