0.3.1 • Published 6 years ago

vase-dev v0.3.1

Weekly downloads
1
License
ISC
Repository
-
Last release
6 years ago

Important Note

This npm package has moved to https://www.npmjs.com/package/vasern and Vasern Github repository.

Note: vase-dev support to be an underdevelopment package, and had been restructured recently

Vasern is a mobile database for React Native, an alternative for SQLite, Realm AsyncStorage, aims to be developer friendly, with high performance.

Types

string, int, double, date, # (reference), ? (optional)

Functions

Vase level:
    - get, filter, exclude
        + by query object
Doc level:
    - filter, exclude, group
        + by query object
    - insert, get, remove, update
        + by object, id, array of objects
    - custom function
Content level:
    - custom function

Schema

- basic data types: string, int, double, date
- reference "#"
- optional "?"
- list "[]"

Example

// Content level classes
class Student {
    age() {
        return (new Date()).getYear() - this.dbo.getYear();
    }
}

// Content level classes
class StudentDoc extends Vasern.Doc {
    prototype = Student;
    name = "Students";

    schema = {
        id: 'string',
        name: 'string',
        dob: 'date',
        subjects: '#Subject[]'
    };

    graduate(year) {
        return this.filter({ dob: "01/01/1995" })
    }
}

class SubjectDoc {
    name = "Subjects";
    schema = {
        id: 'string',
        title: 'string',
        credit: { type: 'int', default: 4 }
    }
}


var db = new Vasern({ schemas: [Student, Subject] });
var { Student, Subject } = db;

// Return a list of new Subject objects
var availableSubjects = Subject.insert([{
    title: "Math",
    credit: 4
}, {
    title: "Geography",
    credit: 4
}]);

// return new Student record object
var anton = Students.insert({
    name: "Antonio",
    dob: "02/07/1967",
    subjects: availableSubjects
})

// Return all
var students = Students.data();

// Return an array that match with the filter
var filteredStudents = Students
    .filter({ dob: "02/07/1967" }) // include results that match the query
    .except({ name: "Hirio" }) // exclude results that match the query
    .group('dob'); // group results by property name

// Return a removed object/s
var removedStudent = Students.remove(anton); // using object
var removedStudentWithId = Students.remove(anton.id); // using id
var removedSubjects = Subject.remove(availableSubjects); // using an array of object

// TODO: What to do with a reference that is removed
// + Return a undefined?

// Batch action
Students.perform(docManager => {

    var veenieo = docManager.insert({
        name: "Veenieo",
        dob: "04/06/1987",
        subjects: availableSubjects
    })

    docManager.update(veenieo, { name: "Julie Veenieo" }) // Using object
    docManager.update(veenieo.id, { name: "Julie Veenieo" }) // Using id
});

// Return 'Student' object with 'subjects' property is a list of subjects
var studentWithSubjects = db.get('Student', { name: "Julie Veenieo" })
var filterStudents = db.filter('Student', { dob: "04/06/2017" })

// === CUSTOM FUNCTIONS === //

// Content level
var veenieo = Students.get({ name: "Julie Veenieo" });
veenieo.age(); // expect an integer number, which present age

// Doc level
var nextGraduages = Students.graduate(2018); // return a list
0.3.1

6 years ago

0.3.0

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.10

6 years ago

0.1.9

6 years ago

0.1.8

6 years ago

0.1.7

6 years ago

0.1.6

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.1

6 years ago