npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ferrydb

v1.0.5

Published

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.

Downloads

46

Readme

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.