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

db2objection

v0.1.15

Published

Generate ObjectionJS models from database tables

Downloads

31

Readme

db2objection

Generate ObjectionJS models from database tables. (Note: This is an ESM package from v0.1.0)

Install

Install cli globally with npm, yarn or your preferred package manager.

$ npm install -g db2objection
# or
$ yarn add global db2objection

Supported databases

db2objection currently supports the following databases:

  • MySQL
  • PostgreSQL
  • SQLite

Commands

Run the commands in the root of the target project that's connecting to the database.

db2obj init

Create the db2objection.config.js file. This should be the first step to using db2objection in your project.

Options

--reset [boolean] Remove existing config file and create a new one.

db2obj generate

Generate ObjectionJS model classes.

Options
Options:

  -t, --table [tables...]  Name of table to generate model for.
  --reset-config           Used with the init command to specify whether to reset the config file if it already exists.
  -c | --case <char>       (snake | camel | ignore) Used with the `generate` command to indicate the name case for the generated model properties.
  --pojo                   Used with the `generate` command to specify whether plain Typescript model classes will be generated, and not classes extending ObjectionJS Model.
  --db, --database <char>  Specify the database to connect to. This overrides the database value that is set in the config file.
  --dir <char>             Specify target directory path relative to the project root.
  -h, --help               display help for command

Commands:
  init                     Generate config file: db2objection.config.cjs and initialize.
  generate                 Generate objection models from db
  gen                      Alias for 'generate'
  test-connection          Test the database connection.
  help [command]           display help for command

The config file

The db2objection.config.js file is a module with the following properties:

module.exports = {
  /**
   * Knex configurations.
   */
  knex: {
    client: '',
    connection: {
      database: '',
      host: '',
      port: 0,
      user: '',
      password: ''
    }
  },

  modelsOutputDir: 'src/obj-models', // Relative path where the objection models should be saved.

  ignoreTables: [], // Tables to be ignored. e.g. migration tables and other tables used by frameworks.

  case: 'camel' // 'camel' | 'snake' | 'ignore'
};

Changelogs

0.1.13

  • Managed singularization - e.g. don't use "datum" for a "data" word singularization.
  • Existing model files are no more overwritten; instead a copy is saved in "<project_root>/__db2obj".

0.1.12

  • Minor bug fixes

0.1.11

  • New cli command: test-connection to check that the db configuration is setup properly.
  • Fix outdated README contents.

0.1.0

  • Convert to ESM package.
  • The dir for generated models will not be deleted anymore. Now, the specific model files will simply be replaced and a copy of the old file be placed in the history folder in the project root.
  • Database name value from cli option flag takes precedence over value in db2objection.config.cjs file.
  • cli update: --case is now a string option, replacing --camelCase.
  • New cli option: --dir to specify where model object files will be generated.
  • Specify multiple tables for --table cli flag