Giter Club home page Giter Club logo

mycro-db's Issues

Proposal: index system

Reading the Readme I found that one of the future plans is to create the index system.

Thinking a little, I believe I came up with a good basis for the system:

API

import { MemoryStorage, MycroDatabase } from 'mycro-db';

const storage = new MemoryStorage();
const db = new MycroDatabase(inMemoryStorage);

const User = db.collection('users', {
    name: String(),
    age: Number()
});
User.index('name');

User.insert([{
        name: 'Alice',
        age: 28
    },
    {
        name: 'Bob',
        age: 30
    }
]);

OBJECT

{
  collections: {
    users: {
      id: 2,
      documents: [
          { id: 1, name: 'Alice', age: 28 },
          { id: 2, name: 'Bob', age: 30 }
      ],
      indexes: {
        // REF: [key]: (value, id)[]
        name: [
          ('Alice', 1),
          ('Bob', 2)
        ]
      }
    }
  }
}

In summary, in addition to CRUD commands, the Collections API can offer a command to create an INDEX under a KEY that you have in your documents.

As MycroDB is not concerned with maintaining something structured, the system can be flexible, and in documents inserted into the collection that do not have the key that is treated as an index, it simply ignores it.

In the same meantime, it would be necessary to rewrite part of the functions to deal with indices. Perhaps in addition to GET by id, it will be possible to have a GET by index. And change the QUERY to search in indexes?

Anyway, I believe that the approximation above is very good for the current MycroDB API.

Feature: Choose ID type

From what I understand, it is not possible to choose the 'type' of data that will be used as an ID in a given collection. I would like this possibility to be added to the API.

Another thing, looking at the code that generates the collection, I saw that it 'automatically' / 'forcibly' attaches the Document ID to its record. Although I haven't messed up anything so far, I believe that doing this without the programmer explicitly stating that he wants to do so is shooting himself in the foot.

Anyway, I would like to have the choice of what type of data I will have as an ID, and for this automated ID system in the Document to be replaced by something less intrusive.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.