diegiwg / mycro-db Goto Github PK
View Code? Open in Web Editor NEWMycroDB is a JavaScript library for managing Document Databases stored in a single JSON file or in-memory.
Home Page: https://diegiwg.github.io/mycro-db/
License: MIT License
MycroDB is a JavaScript library for managing Document Databases stored in a single JSON file or in-memory.
Home Page: https://diegiwg.github.io/mycro-db/
License: MIT License
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.
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.