crudder

Not an ORM. Make CRUD operations easy.


Keywords
database, crud, postgresql
License
MIT
Install
npm install crudder@0.1.4

Documentation

Crudder

Build Status

I don't like ORM tools, but I also don't like to create sql for every simple CRUD operation. This tools generates sql for create, read, update and delete on a single table. For all the rest you need to use the normal driver. This package has no dependencies.

This means no models, joins, order, migrations, ... You can still do this with your normal database drivers.

Examples

Connection

At the moment I only support postgresql, but it is easy to support other databases. Crudder doesn't create a connection, it uses an existing one. This means you can use it in existing projects without rewriting.

const Crudder = require("crudder")
const { Client } = require("pg");
connectionString = "postgresql://user@localhost/somedb";
const client = new Client({ connectionString }); //or Pool
const db = new Crudder({ type: "postgres", client });

You can keep using client or db.client for more complex queries.

Insert (= create)

const item = await db.insertOne({
   table: "items",
   values: {
      description: "laptop",
      price: 603.62
   },
   returning: "id"
})
console.log(item.id)

You can also return multiple fields if you pass an array to returning

Select (= read)

const item = await db.selectOne({
   table: "items",
   where: {
      id: 1
   }
})
console.log(item)

This does a select *, but you can use fields: ["price"] to change this.

Update

const item = await db.updateOne({
   table: "items",
   set: {
      description: "computer",
      price: 433.55
   },
   where: {
      id: 1
   }
})

Delete

const item = await db.deleteOne({
   table: "items",
   where: {
      id: 1
   }
})

License

MIT License

Copyright (c) 2019 Roeland Moors

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.