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 🙏

© 2026 – Pkg Stats / Ryan Hefner

ocr-firebird

v0.1.0

Published

Sequelize-like ORM for Firebird, extracted from Orius ORM.

Readme

ocr-firebird

ORM para Firebird com API inspirada no Sequelize (classes de model, Op, include, hooks, scopes e transações).

Instalação

npm i ocr-firebird node-firebird

node-firebird é o driver de conexão com o Firebird.

Quickstart

1) new OriusORM(...)

import { OriusORM } from 'ocr-firebird';

const orm = new OriusORM({
  host: '127.0.0.1',
  port: 3050,
  database: 'SAOFRANCISCO',
  user: 'SYSDBA',
  password: 'masterkey',
  encoding: 'UTF8',
  maxPool: 10,
  logging: true,
  benchmark: true
});

2) orm.authenticate()

await orm.authenticate();
// Resposta esperada: conexão validada com sucesso.

Definição de modelos

Model.init(...)

import { Model, DataTypes } from 'ocr-firebird';

class G_USUARIO extends Model {}

G_USUARIO.init(
  {
    USUARIO_ID: { type: DataTypes.BIGINT(), primaryKey: true, autoIncrement: true },
    LOGIN: { type: DataTypes.STRING(60), allowNull: false },
    NOME_COMPLETO: { type: DataTypes.STRING(150), allowNull: false },
    EMAIL: { type: DataTypes.STRING(150) }
  },
  {
    tableName: 'G_USUARIO',
    primaryKey: 'USUARIO_ID',
    orm
  }
);

orm.define(...)

import { DataType } from 'ocr-firebird';

const T_ATO = orm.define(
  'T_ATO',
  {
    ATO_ID: { type: DataType.BIGINT, primaryKey: true, autoIncrement: true },
    PROTOCOLO: { type: DataType.BIGINT },
    USUARIO_ID: { type: DataType.BIGINT }
  },
  {
    tableName: 'T_ATO',
    primaryKey: 'ATO_ID'
  }
);

DataTypes e validação (validate)

const Usuario = orm.define(
  'Usuario',
  {
    ID: { type: DataTypes.BIGINT(), primaryKey: true, autoIncrement: true },
    LOGIN: {
      type: DataTypes.STRING(60),
      allowNull: false,
      validate: {
        len: [3, 60]
      }
    },
    EMAIL: {
      type: DataTypes.STRING(150),
      validate: {
        isEmail: true
      }
    },
    STATUS: {
      type: DataTypes.ENUM('A', 'I'),
      defaultValue: 'A'
    }
  },
  { tableName: 'G_USUARIO', primaryKey: 'ID' }
);
// Resposta esperada: dados inválidos em create/save/update disparam ValidationError.

CRUD principal

// CREATE
const novo = await T_ATO.create({
  PROTOCOLO: 12345,
  USUARIO_ID: 1
});

// FIND ALL
const rows = await T_ATO.findAll({
  order: [['ATO_ID', 'DESC']],
  limit: 10
});

// FIND + COUNT (paginação)
const page = await T_ATO.findAndCountAll({
  limit: 10,
  offset: 0,
  order: [['ATO_ID', 'DESC']]
});

// COUNT
const total = await T_ATO.count({
  where: { USUARIO_ID: 1 }
});

// UPDATE (estático)
const [affected] = await T_ATO.update(
  { PROTOCOLO: 99999 },
  { where: { ATO_ID: novo.dataValues.ATO_ID } }
);

// DESTROY (estático)
const deleted = await T_ATO.destroy({
  where: { ATO_ID: novo.dataValues.ATO_ID }
});

Transações

await orm.transaction(async (tx) => {
  const ato = await T_ATO.create(
    { PROTOCOLO: 777, USUARIO_ID: 1 },
    { transaction: tx }
  );

  await T_ATO.update(
    { PROTOCOLO: 778 },
    { where: { ATO_ID: ato.dataValues.ATO_ID }, transaction: tx }
  );
});
// Resposta esperada: commit automático se tudo der certo, rollback se houver erro.

Transação aninhada (savepoint)

await orm.transaction(async (txPai) => {
  await orm.transaction({ transaction: txPai, savepointName: 'SP1' }, async (txNested) => {
    await T_ATO.create({ PROTOCOLO: 888, USUARIO_ID: 1 }, { transaction: txNested });
  });
});

Associações

G_USUARIO.hasMany(T_ATO, {
  as: 'atos',
  foreignKey: 'USUARIO_ID',
  sourceKey: 'USUARIO_ID'
});

T_ATO.belongsTo(G_USUARIO, {
  as: 'usuario',
  foreignKey: 'USUARIO_ID',
  targetKey: 'USUARIO_ID'
});

Consultas com where, include, includes aninhados e operadores

import { Op } from 'ocr-firebird';

const atos = await T_ATO.findAll({
  where: {
    [Op.or]: [{ SITUACAO_ATO: '1' }, { SITUACAO_ATO: '2' }],
    ATO_ID: { [Op.gt]: 1000 },
    PROTOCOLO: { [Op.notIn]: [10, 20, 30] }
  },
  include: [
    {
      association: 'usuario',
      as: 'usuario',
      attributes: ['USUARIO_ID', 'LOGIN', 'NOME_COMPLETO']
    }
  ],
  order: [['ATO_ID', 'DESC']],
  limit: 20
});

Include aninhado

const result = await T_ATO.findAll({
  include: [
    {
      association: 'usuario',
      as: 'usuario',
      include: [
        {
          association: 'perfil',
          as: 'perfil'
        }
      ]
    }
  ],
  limit: 10
});

Include com separate: true

const users = await G_USUARIO.findAll({
  include: [
    {
      association: 'atos',
      as: 'atos',
      separate: true,
      limit: 10,
      order: [['ATO_ID', 'DESC']]
    }
  ]
});

Hooks

T_ATO.beforeCreate((instance) => {
  instance.set('SITUACAO_ATO', instance.get('SITUACAO_ATO') ?? '1');
});

T_ATO.afterCreate((instance) => {
  console.log('Ato criado:', instance.get('ATO_ID'));
});

T_ATO.beforeUpdate((instance) => {
  console.log('Antes de atualizar:', instance.get('ATO_ID'));
});

T_ATO.afterUpdate((instance) => {
  console.log('Depois de atualizar:', instance.get('ATO_ID'));
});

T_ATO.beforeDestroy((instance) => {
  console.log('Antes de remover:', instance.get('ATO_ID'));
});

T_ATO.afterDestroy((instance) => {
  console.log('Depois de remover:', instance.get('ATO_ID'));
});

Encerramento da conexão

orm.close();

Build local da lib

No repositório raiz:

npm run build:orm

Publicação no npm

cd packages/orm
npm publish --access public