Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ferrydb

Package Overview
Dependencies
Maintainers
0
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ferrydb

FerryDB is a simple, flexible, and powerful SQLite-based ORM for Node.js. It allows you to define schemas, validate data, and perform CRUD operations with ease.

  • 1.0.5
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
15
increased by150%
Maintainers
0
Weekly downloads
 
Created
Source

FerryDB

FerryDB is a simple, flexible, and powerful SQLite-based ORM for Node.js. It allows you to define schemas, validate data, and perform CRUD operations with ease.

Table of Contents

Installation

To install FerryDB, run:

npm install ferrydb

Usage

Here's a quick example of how to use FerryDB:

import { Schema, model, connect } from 'ferrydb';

// Connect to the database
connect('path/to/your/database.sqlite');

// Define a schema
const userSchema = new Schema({
    name: { type: 'string', required: true },
    age: { type: 'number', required: true }
});

// Create a model
const User = model('User', userSchema);

// Create a new user
const newUser = User.create({ name: 'John Doe', age: 30 });

// Find a user
const user = User.findOne({ name: 'John Doe' });

// Update a user
User.update({ name: 'John Doe' }, { age: 31 });

// Delete a user
User.delete({ name: 'John Doe' });

API Reference

connect(pathToDb: string)

Connect to the SQLite database.

  • pathToDb: The path to the SQLite database file. Must end with .sqlite.

Schema

Create a new schema for your data model.

const userSchema = new Schema({
    name: { type: 'string', required: true },
    age: { type: 'number', required: true }
});
validate(data: Partial<InferSchema<T>>, isCreate: boolean = false)

Validate the data against the schema.

  • data: The data to validate.
  • isCreate: Whether this is a create operation. Default is false.

model

Create a new data model.

const User = model('User', userSchema);
create(data: Partial<InferSchema<T>>): ModelInstance<InferSchema<T>>

Create a new record in the database.

  • data: The data to create.
findOne(conditions: QueryConditions<InferSchema<T>>): ModelInstance<InferSchema<T>> | null

Find a single record matching the conditions.

  • conditions: The conditions to match.
findAll(conditions: QueryConditions<InferSchema<T>>): ModelInstance<InferSchema<T>>[]

Find all records matching the conditions.

  • conditions: The conditions to match.
find(): ModelInstance<InferSchema<T>>[]

Find all records in the database.

update(conditions: QueryConditions<InferSchema<T>>, data: Partial<InferSchema<T>>): number

Update records matching the conditions.

  • conditions: The conditions to match.
  • data: The data to update.
delete(conditions: QueryConditions<InferSchema<T>>): number

Delete records matching the conditions.

  • conditions: The conditions to match.

Examples

Creating a New Record

const newUser = User.create({ name: 'John Doe', age: 30 });

Finding a Record

const user = User.findOne({ name: 'John Doe' });

Updating a Record

User.update({ name: 'John Doe' }, { age: 31 });

Deleting a Record

User.delete({ name: 'John Doe' });

Finding a Record with Condition Function

const user = User.findOne({ name: x => x.startsWith("John ")  });

Updating Records with Condition Function

User.update({ name: x => x.startsWith("John ") }, { age: 31 });

Deleting a Record with Condition Function

User.delete({ name: x => x.startsWith("John ") });

Support

If you need help or have questions, feel free to join our Discord community.

Developer

FerryDB is developed and maintained by ferrymehdi.

Keywords

FAQs

Package last updated on 17 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc