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

@ackee/databless

v3.0.0

Published

A work-in-progress set of yet-bookshelf-only DB helpers and a generic repository.

Downloads

13

Readme

Build Status Known Vulnerabilities

Databless

Relational database gateway

Providing means of communications with relational database.

Based on Ackee's former rdgw defaultRepository module.

Features

  • (Bookshelf) automatic column cache and attributes stripping on first model use
  • (Bookshelf) No default after-update fetch
  • (Bookshelf) Optional Id support (not all models have an id attribute)
  • (Bookshelf) Automatic offset/limit, page/pageSize option parse
  • (Bookshelf) Automatic options-based support for ordering, e.g. -id (sort by id descending). May be an array of those. Use + for ascending.

Quickstart

Knex/Bookshelf


const {
    // Initializes knex with given options and stores the instance
    // under given key. No key means default instance.
    initKnex,
    // Initializes bookshelf with given options and stores the instance
    // under given key. No key means default instance.
    initBookshelf,
    // To register bookshelf models from a directory
    registerBookshelfModels,
    // Gets an knex instance by given key. No key means the default instance.
    getKnex
    // Gets a bookshelf instance by given key. No key means the default instance.
    getBookshelf
} = require('rdbgw');

const register = (...args) =>
    registerBookshelfModels(
        initBookshelf(
            initKnex(config.bookshelf.knex.init)
        ),
    ...args)

// Read all the models to the bookshelf registry
// All model modules are expected to be a fn (bookshelf): Model
register(`${__dirname}/app/models`);
const {
    // General repository
    defaultBookshelfRepository,
    getBookshelf,
} = require('rdbgw');

const Availability = getBookshelf().model('Availability');

const availabilities = (({ detail, create, updateById, deleteById, bulkCreate, list }) => (
    {
        list,
        bulkCreate,
        detail,
        create,
        updateById,
        deleteById,
    }
))(defaultBookshelfRepository.bind(getBookshelf(), Availability));

availabilities.create({ from: new Date() });

availabilities.list({});

availabilities.list({}, { qb: (qb) => qb});

/*
defaultBookshelfRepository's API

bulkCreate: (bookshelf, Model, data, options): Promise

create: (bookshelf, Model, data, options): Promise

delete: (bookshelf, Model, query, options): Promise

deleteById: (bookshelf, Model, id, options):
    delete(bookshelf, Model, { id }, options)

list: (bookshelf, Model, query, options): Promise

detail: (bookshelf, Model, query, options):
    list(bookshelf, Model, query, { ...options, limit: 1, offset: 0 })

detailById: (bookshelf, Model, id, options):
    detail(bookshelf, Model, { id }, options)

update: (bookshelf, Model, query, data, options): Promise

updateById: (bookshelf, Model, query, data, options):
    update(bookshelf, Model, { id }, data, options)

--
bind: (bookshelf, Model) returns an object with API of above with bound bookshelf instance and Model.

--
.withDetail* helpers - Returns a function of given call, successful call triggers a detail call with given query, returning this result instead.

create.withDetailBy(query) 
create.withDetailById(id)
update.withDetailBy(query)
update.withDetailById(id)
*/

Helpers

  • composeQb - composeQb(options, qb => ...) automatic wrap for composing multiple querybuilders in different layers of the application. Prevents qb option overwriting.