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

oracle-orm

v0.1.9

Published

An Oracle ORM that actually works

Downloads

19

Readme

oracle-orm

Because the other options are worse.

There's only one other ORM for Node.js that supports Oracle. It says a lot about the cultures of both Node and Oracle.

The other ORM has over a year of open issues on Github, it sometimes generates invalid Oracle SQL statements and does absurd things like creating a table PEOPLE for a model named PERSON (and PEOPLES for PEOPLE, ha). I don't like ORMs, I'm forced to use one for a project. I don't want my tools to do unexpected things in the database and that other ORM is full of surprises.

Oracle-ORM is safe against SQL injections.

This ORM only supports the features I need. It doesn't support connection pooling, error recovery and all sorts of basic things you'd expect from an ORM. If you want those features added, open an issue or send a pull request.

Install

Don't install from npm yet!

First, make sure libaio is installed: sudo apt-get install libaio1 or sudo yum install libaio

Then, go to the Oracle driver page and select your architecture. Download instantclient-basic-linux.x64-12.1.***.zip and instantclient-sdk-linux.x64-12.1.***.zip.

Unzip both into YOUR_PROJECT/instantclient_12_1. It won't work if the driver can't be found.

Run npm install oracle-orm in your project's directory. It'll prompt for sudo because the Oracle driver needs environment variables.

Finally, run source /etc/environment (or just logout and log back in). All done!

Run the tests

Put the database credentials in node_modules/oracle-orm/testDB.json and run npm test oracle-orm.

Usage

var ORM = require("oracle-orm");
var oracleConnectData = {
	driver: "oracle"
	hostname: "hostname or IP"
	port: 1521
	database: "database name (SID)"
	user: "username"
	password: "password123"
};
var debug = true;

new ORM(oracleConnectData, debug, function(err, orm){
	orm.getModels(function(err, models){
		// do stuff with the models
	});
});

Due to the very callback-heavy nature of SQL, it's recommended to use a tool to deal with that. Promises, Generators, Streamline, Q, Async, etc. are all good options.

Documentation

Oracle-ORM works by building one Model object per table in the database. Operations on that Model affect the whole table. Operations GET and ALL on a Model return new copies of Units. A Unit maps to a database row. There can be more than one Unit per row. Operations on a Unit only affect that row.

ORM

Getting the Models

orm.getModels(function(err, models){
	//do something with the models
});

Running arbitrary SQL

orm.execute(sql, paramsArray, function(err, results){ ... });

Model

In these examples, USER is a Model.

The USER.columns object contains information about the field types.

add

USER.add({"USER_ID":5, "NAME":"JOE SMITH"}, function(err, results){ ... });

get

// USER_ID between 5 and 20
USER.get({"USER_ID":">5", "USER_ID":"<20"}, [], function(err, results){ ... });

// All users, ordered by USER_ID ascending and NAME descending
USER.get({}, ["USER_ID ASC", "NAME DESC"], function(err, results){ ... });

all

// Shortcut for .get({}, [], cb);
// all() returns Units in a non-deterministic order
USER.all(function(err, results){ ... });

update

// Apply change to the whole table
// Change all "JOE SMITH" with USER_ID greater than 10 to "BOB SMITH"
USER.update({"NAME":"BOB SMITH"}, {"NAME":"='JOE SMITH'", "USER_ID":">10"}, function(err, results){ ... });

del

// Delete everything with a USER_ID smaller than 5
USER.del({"USER_ID":"<5"}, function(err, results){ ... });

count

USER.count(function(err, results){ ... });

empty

USER.empty(function(err, results){ ... });

Unit

data

user.data contains the fields and values of a Unit.

isDirty

Returns true if the object was modified

save

Writes the dirty (modified) fields to the database.

sync

Refreshes all fields with fresh values from the database.

reset

Brings all fields back to the state they were in when the Unit was created or after the last sync if sync was called at some point.

Examples

In these examples, user55 is a Unit. Suppose they are executed sequentially.

user55.isDirty(); // false
user55.data.NAME = "WILLIAM CAMPBELL";
user55.isDirty(); // true
user55.save(function(err, results){ ... });
user55.isDirty(); // false
console.log(user55.data.NAME); // "WILLIAM CAMPBELL"

user55.data.NAME = "JAMES SMITH";
user55.isDirty(); // true
console.log(user55.data.NAME); // "JAMES SMITH"
user55.sync(function(err, results){ ... });
console.log(user55.data.NAME); // "WILLIAM CAMPBELL"
user55.isDirty(); // false

user55.data.NAME = "JAMES SMITH";
user55.isDirty(); // true
console.log(user55.data.NAME); // "JAMES SMITH"
user55.reset(function(err, results){ ... });
console.log(user55.data.NAME); // "WILLIAM CAMPBELL"
user55.isDirty(); // false


user55.del(function(err, results){ ... }); // Deleted from the database
user55.del(function(err, results){ ... }); // Uncaught Exception: 'Unit USER was deleted and doesn't exist anymore'