1.0.7 • Published 2 years ago

borgoose v1.0.7

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Borgoose

Borgoose is great database management library for small projects. With Borgoose, you can easily store your data in a local JSON file, which makes it easy to access and use.

Borgoose takes functions from Mongoose. This will make it easy for you to migrate your project to MongoDB in the future.

npm version CodeFactor

image


Install

npm i borgoose

Functions


Usage

new Borgoose(path, options)

const Borgoose = require('borgoose')
// default value of syncOnWrite is true
// I'm just writing you to see that such a setting exist :)
const bdb = new Borgoose('db.json', { syncOnWrite: true, createWithId: true })

Options

OptionTypeDescriptionDefault
syncOnWriteBooleanAutomatically saves data to JSON file after each modificationtrue
createWithIdBooleanAutomatically generate ID when you create new Objectfalse

Examples

Insert (Create)

// Create single data
bdb.insertOne({ name: 'Bora', age: 19 })

// Create multiple data
bdb.insertMany([
	{ name: 'Burak', age: 19 },
	{ name: 'Baris', age: 26 },
])

Find (Read)

// Find single data
bdb.findOne({ age: 19 })

// Find by ID
bdb.findById('b0df200b-00f3-4a5b-8389-233e928e84e6')

// You can also use functions
bdb.findOne((o) => o.age > 25)

// Find multiple data
bdb.findMany({ age: 19 })

// Get all data
bdb.findMany()

Update

// Update single data
// It will set the age value of the data whose 'name' key is 'Bora' to 20.
bdb.updateOne({ name: 'Bora' }, { age: 20 })

// Update multiple data
// This will set the age values ​​of all data less than 18 years old as 20.
bdb.updateMany((o) => o.age < 18, { age: 20 })

Delete

// Delete single data
bdb.deleteOne({ name: 'Bora' })

// You can also use functions
bdb.deleteOne((o) => o.age < 20)

// Delete multiple data
bdb.deleteMany((o) => o.age < 20)

Write

// Replace all data with specified in parameter
bdb.write([{ name: 'Bora' }])

Shuffle

// Shuffle data
bdb.shuffle()

Sync

// If syncOnWrite setting is false you have to use it to print data to json file.
bdb.sync()

Developer Notes

  • Use MongoDB.
1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago