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

relax-orm

v1.2.1

Published

ORM for OracleDB

Downloads

24

Readme

Relax ORM

npm version Build Status codecov


A lite ORM Designed to reduce the stress you feel while leading with OracleDB.
Inspired by Sequelize and SequelizeTypescript Please see change log to checkout new functions.

ChangeLog | TypeScript Demo App

Getting started

Relax ORM depens on OracleDB instant client. Please follow the instruction. Official: OracleDB Client Install Guid

After installing the OracleDB client, run the script below on terminal.

npm i oracledb relax-orm -S

Creating Connection and Entities

To create an Entity, you just extends Entity class and declare the generics type like example. Also you need to declare table name with @Table, one @PrimaryKey and Columns. Optionaly you can declare the use of sequence witch will be used on INSERT.

@Table('USER_TABLE')
export class User extends Entity<User>{

  @PrimaryKey() // Each entity requires one PrimaryKey to use 'save' function
  @Sequence('USER_SEQUENCE')
  @Column('USER_ID')
  id?: number;

  @Column()
  name?: string;
}

After creating Entities, you need to create and initialize connection and registering Entities.

const conn = new ConnectionManager({
  user          : DBCONFIG.user,
  password      : DBCONFIG.password,
  connectString : DBCONFIG.connectString,
});
conn.addEntities([ User ]);
await conn.init();

Optionaly you can change oracledb config before creating ConnectionManager

ConnectionManager.config.maxRows = 100;
ConnectionManager.config.fetchAsString = [ oracledb.DATE, oracledb.NUMBER ];
const conn = new ConnectionManager({...You Connection Config});

Query Example

After registering you can use the basic queries.

User.findAll()
/* Generages: 
SELECT SEQ_NUM_USER, NAME
  FROM RLXORM.TB_USE
*/

User.findAll( {where: { id: 1, name: 'walker' } });
/* Generages: 
SELECT SEQ_NUM_USER, NAME
  FROM RLXORM.TB_USER
 WHERE SEQ_NUM_USER = :id$ AND NAME = :name$
*/

User.create({
  id: 10, // If @Sequence is declared, this value will be ignored
  name: 'walker'
})
/* Generages: 
INSERT
      INTO RLXORM.TB_USER ( SEQ_NUM_USER, NAME )
    VALUES ( RLXORM.SQ_USER.NEXTVAL, :name$ )
 RETURNING SEQ_NUM_USER, NAME
      INTO :out$id, :out$name
*/

// Saving entity
const user = User.findOne({ where: {id: 1} });
/* Generages: 
SELECT SEQ_NUM_USER, NAME FROM RLXORM.TB_USER WHERE SEQ_NUM_USER = :id$
*/

user.name = 'style';
user.save();
/* Generages: 
UPDATE RLXORM.TB_USER SET SEQ_NUM_USER = :id$, NAME = :name$ WHERE SEQ_NUM_USER = :key$id RETURNING SEQ_NUM_USER, NAME INTO :out$id, :out$name
*/

User.destroy({
  name: 'walker'
});
/* Generages: **NOTE** IT WILL DELETE RECORDS USING WHERE FILTER
DELETE FROM RLXORM.TB_USER WHERE NAME = :name$
*/


User.destroyAll();
/* Generages: **NOTE** IT WILL DELETE ALL RECORDS FROM TABLE
DELETE FROM RLXORM.TB_USER
*/

Query FindOptions

In findAll and findOne queries you can use options and combine them like examples below.

let res = await User.findAll({
  where: {
    [Op.or]: [
      { id: 10 },
      { id: 11 },
    ],
    name: 'walker',
  },
});
/* Generates:
SELECT SEQ_NUM_USER, NAME
  FROM RLXORM.TB_USER
 WHERE ( SEQ_NUM_USER = :id$ )
    OR ( SEQ_NUM_USER = :id$ )
   AND NAME = :name$
*/

res = await User.findOne({
  where: {
    [Op.and]: [
      { id: 10 },
      { name: 'walker' },
    ],
  },
});
/* Generates:
SELECT SEQ_NUM_USER, NAME
  FROM RLXORM.TB_USER
 WHERE ( SEQ_NUM_USER = :id$ )
   AND ( NAME = :name$ )
*/


res = await User.findAll({
  order: [
    [ 'id',ResultOrder.ASC ],
    [ 'name',ResultOrder.DESC ]
  ]
});
/* Generates:
SELECT SEQ_NUM_USER, NAME
  FROM RLXORM.TB_USER
 ORDER BY SEQ_NUM_USER ASC, NAME DESC
*/

res = await User.findAll({
  where: {
    name: 'walker',
  },
  order: [
    [ 'id',ResultOrder.ASC ],
    [ 'name',ResultOrder.DESC ],
  ],
});
/* Generates:
SELECT SEQ_NUM_USER, NAME
  FROM RLXORM.TB_USER
 WHERE NAME = :name$
 ORDER BY SEQ_NUM_USER ASC, NAME DESC
*/

res = await User.findAll({
  limit: 2,
});
/* Generates:
SELECT SEQ_NUM_USER, NAME
  FROM ( SELECT SEQ_NUM_USER, NAME, ROWNUM as TMP$ROWNUMBER
  FROM RLXORM.TB_USER )
 WHERE TMP$ROWNUMBER <= :TMP$LIMIT
 */

res = await User.findAll({
  limit: 2,
  order: [['name', ResultOrder.ASC]],
});
/* Generates: it uses ROW_NUMBER function with over to use ordered result
SELECT SEQ_NUM_USER, NAME
  FROM( SELECT SEQ_NUM_USER, NAME, ROW_NUMBER()
  OVER( ORDER BY NAME ASC ) as TMP$ROWNUMBER
    FROM RLXORM.TB_USER ORDER BY NAME ASC )
   WHERE TMP$ROWNUMBER <= :TMP$LIMIT
*/

res = await User.findAll({
  order: [['id', ResultOrder.ASC]],
  offset: 1,
  limit: 2,
});
/* Genarates
SELECT SEQ_NUM_USER, NAME
  FROM ( SELECT SEQ_NUM_USER, NAME, ROW_NUMBER()
  OVER( ORDER BY SEQ_NUM_USER ASC ) as TMP$ROWNUMBER
     FROM RLXORM.TB_USER ORDER BY SEQ_NUM_USER ASC )
    WHERE TMP$ROWNUMBER > :TMP$OFFSET
      AND TMP$ROWNUMBER <= :TMP$LIMIT
*/


res = await User.findAll({
  where: {
    [Op.or]: [
      { id: { [Op.in]: [userWalker.id, userKoji.id] } },
      { name: userRelax.name },
    ],
  },
});
/* Generates
SELECT SEQ_NUM_USER, NAME FROM RLXORM.TB_USER
 WHERE ( SEQ_NUM_USER IN ( :id$in$0, :id$in$1 ) )
    OR ( NAME = :name$ )
*/