Skip to main content

Local Document Oriented Database

Project description

JLOD stands for JSON Local Document Database, it is a serverless in-process library that implements a self-contained document-oriented database use for storing small application data within an application without internet connection. The database is like MongoDB, it uses Collection, Document, and JSON objects. The JLOD is a version of SQLite for object oriented data, the JLOD collections can be exported to Remote MongoDB collection as well as remote MongoDB collection can also be imported to the JLOD database.

JLOD is an embedded document-oriented database library. Unlike MongoDB. JLOD does not have a separate server process. JLOD reads and writes the data to ordinary disk files. The complete JLOD database along with the collections and the documents are contained in a disk file. The folder is a database in JLOD while the file is a collection, and each object is a document.

Audience

This library will be quite helpful for all those developers who want to develop serverless web applications using Python. It is meant for programmers with a stronghold on MongoDB concepts.

Prerequisite

The library assumes that the readers have adequate exposure to MongoDB or any document-oriented database concepts. If you have worked on MongoDB, then it will help you further to grasp the concepts of the library quickly.

Copyright & Disclaimer

  1. Any user is permitted to reuse, distribute this library
  2. Any user can contribute to this library

Features of the JLOD Library

• Self Contained

• Performance

• Serverless

• Installation

• Create Database

• Create Collection

• Add Documents

• Drop Collection

• Collection Size

• Get Documents

• Query Documents

• Sorting and Distinct

• Remove Document

• Update Document

• Truncate Collection

• Export Collection

• Import Collection

Self Contained

JLOD database stored data in a folder within an application, once the application is hosted to any server or build by any compiler, the database will remain along with the application. And data can be stored and retrieved without an internet connection.

  1. Folder is a database
  2. File is a Collection
  3. Object is a Document

Performance

Since the JLOD database stored data in a local folder within an application, the performance is extremely awesome. The application will not need to initiate an internet connection to access the stored data.

Serverless

Since the JLOD database stored data in a local folder within an application, there is no need for a server. The database stored where ever the application is hosted.

Structure

JLOD library creates a folder as a Database and creates a file as a collection then adds a JSON array of objects to the files as a group of documents.

Installation

$ pip install jlod

 from jlod import database

 dbi = database.connect('test').instance
 client = dbi.collection('users')

 # Add many  documents to a collection
 added = client.addMany([
	{"name": "Jhon", "gender": "Male", "age": 24, "city": "New Delhi", "country": "India"},

	{"name": "Zee", "gender": "Female", "age": 20, "city": "Lagos", "country": "Nigeria"}, 

	{"name": "Frank", "gender": "Male", "age": 27, "city": "Toronto", "country": "Canada"}
 ])
 if added:
	print("Documents Added")
 else:
	print("Failed to add Document")

 # Get all  documents of a collection
 result = client.documents
 for doc in result:
    print(doc)

 # Find document where  "name" is  "Rabie" or "age" is "20"
 result = client.find({
  "$or": [{"name": {"$eq": "Rabie"}}, {"age": {"$eq": 20}}]
 })

 # Get specific single from  documents where name is Jhon or age is 24
 result = client.get(['name'], {
	"name": "Jhon",
	"age": 24
 })

#Get multiple keys
 result = client.getOne(['name', 'age'], {
	 "name": "Jhon",
	 "age": 24
 })

Query Documents There are two types of logical Operators in JLOAD:

  1. AND

  2. OR AND => returns document that matches all given conditions OR=> returns documents that match any of the given conditions

    result = client.find({ "$and": {"name": {"$eq": "Rabie"}} })

Using the AND operator. Above will find any document that has key “name” and value equal to “Rabie”

result = client.find({
     "$or": [{"name": {"$eq": "Rabie"}}, {"age": {"$eq": 20}}]
})

Using the OR operator. Above will get any document that has a key name as “Rabie” or age as “23” in the collection.

result = client.findOne()

Above will return first one document from the entire collection.

result = client.findOne({
      "$and": {"age": {"$gt": 24}}
})

Above will return the first one document that has key “age” with value greater than 24.

Sorting and Distinct

  1. Sorting is used in sorting data in certain format Accending or Descending.

see examples below

result = client.sort({"age": -1})

Above will sort all documents base on key “age” Deceinding order.

result = client.sort({"name": 1},{
  "$and": {"age": {"$eq": 20}}
})

Above will sort all documents base on key “name” Accending order for all documents that has key “age” with value equal to 20.

  1. Distinct is used to get distinct data from a collection with no duplicate.

    result = client.distinct()

Above will return the distinct documents

result = client.distinct({
 "$and": {"city": {"$eq": "Los Angeles"}}
})

Above will return the distinct documents for any document that has key “city” with value “Los Angels”

Remove Document In JLOD remove is used to remove the entire or specific document from a collection,

see examples below.

client.remove()

client.removeAll()

Output: True Anyone of the above will remove all documents in the collection

result = client.remove({
	  "$and": {"name": {"$eq": "Jhon"}}
})

Output: True Above will remove any document that has key “name” with value “Jhon” from the collection

result = client.remove({
   "$or": {"age": {"$gt": 27}}
})




    	Output: True

Above will remove any document that has key “name” with a value greater than “27”

Update Document JLOD update is used in updating documents of a specific collection. see examples below.

client.update({
     "name": "Mary",
	     "age": 20
})

Output: True Above will update the key “name” to “Mary” and age to “20” for all documents in the collection. And if the key age doesn’t exist in the collection, it will be created

result = client.update( {"name": "Jhon", "age": 24},{
		"$and": {"city": {"$eq": "Los Angeles"}}
})

Output: True Above will update the name to “Jhon” and age to “24” on any document that has a city equal to “Los Angeles”.

Truncate Document

result = client.truncate

Output: True Above will remove all documents in the collection

Export Collection Export is used to export the entire or specific document in a JLOD collection to remote MongoDB see examples below.

from jlod import database
import pymongo

dbi = database.connect('example').instance
client = dbi.collection('users')

host = pymongo.MongoClient("mongodb://localhost:27017/")
mydb = host["example"]
mongoClient = mydb["users"]

result = client.exportTo(mongoClient)

Output: True The above will export all the documents in JLOD users collection to MongoDB users collections.

result = client.exportTo(mongoClient, {
  "$and": {"name": {"$eq": "Zee"}}
})

Output: True Above will export any document that contains a name with value “Zee” from the JLOD users collection to remote MongoDB users collections.

Import Collection Import is used for importing entire or specific documents from the remote MongoDB collection to JLOD local database collection. See the examples below.

from jlod import database
import pymongo

dbi = database.connect('example').instance
client = dbi.collection('users')

host = pymongo.MongoClient("mongodb://localhost:27017/")
mydb = host["example"]
mongoClient = mydb["users"]

result = client.importFrom(mongoClient)

Above will import all the documents from remote MongoDB users collections to JLOD users collection

result = client.importFrom(mongoClient, { "$and": {"name": {"$eq": "Zee"}} })

Above will import any document that contains key “name” with value “Zee” from the remote MongoDB users collections to JLOD users collection

End of the library documentation If you want to contribute or discover any errors or suggestions on the code or logic, please notify us at contact@jload.org.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jlod-2.0.1.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jlod-2.0.1-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file jlod-2.0.1.tar.gz.

File metadata

  • Download URL: jlod-2.0.1.tar.gz
  • Upload date:
  • Size: 11.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

File hashes

Hashes for jlod-2.0.1.tar.gz
Algorithm Hash digest
SHA256 0fa2dcbf0fc1805df831e27f22b0c614a66c056fc59b5e26186db9b2a19aa115
MD5 42c6e17926229aa40c890cd21e908d76
BLAKE2b-256 126dc14d870fc7dc8e8059dd7ee647da20cf1b2b4e288386108be0dbb8227286

See more details on using hashes here.

File details

Details for the file jlod-2.0.1-py3-none-any.whl.

File metadata

  • Download URL: jlod-2.0.1-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

File hashes

Hashes for jlod-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2cc4b6b7ef26115a779a395b2c94e848019f8756cacf9ede8dca8dc7707faf62
MD5 3f7f3dbf103a3d58005099c1dee2c71d
BLAKE2b-256 419f5709ff4de477285f83169cb12f6a8c7e8e8b6fdb37454791bc294dc0ad95

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page