databased

1.0.7 • Public • Published

Welcome to DataBASED!

DataBASED is a free, open source database library for Node.js packaged with NPM. It simplifies databases for any small project that doesn't need a more scalable solution. All you have to do is install it (npm install databased) and use the provided commands to set up your database within your own Node server. No API keys, no websites, and it's all free. The only drawback is that it is not scalable to large projects that have a lot of documents within the collections. It will be very slow if you have more than, say, 10,000 documents within a single collection. This is because the indexing system that I implemented is primitive, it still requires iteration to a decent extent, but it is better than nothing. I may or may not continue work on this project, but if I do, here are the things I will improve/change:

  • Make it scalable (basically requires a full re-do) OR just make it more scalable, by improving the indexing system
  • Make an API for easy front end use without any backend (similar to Firestore client side SDK)

Basically, this database is aimed at small projects such as a blog website where you might want to upload some content yourself, but others will not need to post. Or maybe a project where you need to store some information only for a short period of time and then delete it, such as a shopping cart or a contact form.

If you'd like to donate to support development of DataBASED, you can do so by any of the following methods:

ANNOUNCEMENTS

There are none!

1.0.4 CHANGE-LOG

  • Fixed index overwriting bug

Documentation:

Setup

To create your first database, go to the terminal and use this command: npx create-database {database_name}

Then, you can create your first collection within that database using this command: npx create-collection {new_collection_name} {database_name}

A new folder called "databased" will be added to your project's root directory. Do not delete or move it. You can create as many databases, collections, and documents as you need.

If you want to backup your database, you can use 'npx backup-database {db_name}'. Just make sure to set the 'backup_path' value in './databased/settings.json' to your desired directory for backups.

Functions

Query()

The query() function takes 4 arguments: databaseName, collectionName, condition, and limit. All are required except limit.

All main functions (excluding parameter functions, e.g. limit()) are asynchronous, including query().

Example: const query = await query('db1', 'col1', where('Test1', '==', 'test1'), limit(5))

Limit()

The limit() function takes 1 argument of type number. It simply returns the number, you can also just put the number directly into the main function if readability is not a priority.

Where()

The where() function takes 3 arguments: property, operator, and value. The property argument should be the key of the field you are targeting within a document. The operator argument should be a comparison operator such as: '==', '>', '<', '<=', or '>='. The value argument should be the value of the field you want to check.

The function simply returns an object like this: { property: propertyArg, operator: operatorArg, value: valueArg }. Similar to the limit() function, you can just place an object straight into the main function if readability is not a priority.

getDoc()

The getDoc() function takes 3 arguments: databaseName, collectionName, and documentName. It always returns an object with the exists() method, but only returns the data() method if the document exists. The getDoc().exists() method will return either true or false depending on if the document was found in the collection specified. The getDoc().data() method will return the document.

setDoc()

The setDoc() function takes 4 arguments: databaseName, collectionName, documentName, and documentObject. It will either create a new document or overwrite an existing document depending on if one with the name specified already exists in the collection. The documentObject object should be an object with whatever fields you want to insert.

WARNING: setDoc() will not automatically fill in the fields that you leave out when overwriting a pre-existing document, it will simply overwrite it with the new data.

updateDoc()

The updateDoc() function takes 4 arguments, it is the same as the setDoc() function except it will only overwrite the fields you change. You can simply pass in an object that only contains one field, and the rest of the document will remain the same besides that one field, which will either be changed or added depending on if it existed prior to calling updateDoc().

deleteDoc()

The deleteDoc() function takes 3 arguments: databaseName, collectionName, and documentName. As the name suggests, it simply deletes the document if it exists in the collection specified. If there is no document found, it throws an error.

getCollection()

The getCollection() function takes 3 arguments: databaseName, collectionName, and limit (optional). It will return all the documents within the specified collection, unless you use limit() to set the max amount of documents.

Package Sidebar

Install

npm i databased

Weekly Downloads

2

Version

1.0.7

License

ISC

Unpacked Size

32.2 kB

Total Files

8

Last publish

Collaborators

  • trevoltiv