sophie-orm
v1.0.3
Published
A simple and lightweight PostgreSQL ORM for Node.js named after a great cat
Maintainers
Readme
sophie-orm/
├── package.json
├── README.md
└── lib/
└──sophie-orm.js
└──base.jsSophieORM
A lightweight PostgreSQL ORM for Node.js with support for named after a great cat:
- Upserts
- IN and BETWEEN queries
- Coming soon: Batch inserts and upserts
- Transactions
- Joins
- Custom SELECT fields
- Schema definition
Installation
npm install sophie-orm
Sample Usage
const SophieORM = require('sophi-orm').SophieORM;
const crypto = require("crypto");
const userORM = new SophieORM({
config: {
user: "postgres",
host: "localhost",
database: "yourdatabasename",
//password: 'yourpassword',
port: 5432,
},
table: "users",
pk: "id",
model: {
id: "SERIAL PRIMARY KEY",
name: "TEXT",
email: "TEXT UNIQUE",
},
});
(async () => {
const userId = crypto.randomBytes(16).toString("hex");
const profileId = crypto.randomBytes(16).toString("hex");
// Create
await userORM.create({
id: userId,
name: "Flubbernut",
email: "[email protected]",
});
// Find
const user = await userORM.findById(userId);
console.log(user);
const usersWithProfiles = await userORM.findAll(
{ name: { like: '%Schmoo%' } },
{
fields: ['users.id', 'users.name', 'profiles.bio'],
joins: [
{
table: 'profiles',
on: 'users.id = profiles.user_id',
type: 'LEFT'
}
],
orderBy: 'users.id ASC'
}
);
console.log(usersWithProfiles);
})();
