Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

secondthought

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

secondthought - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

5

lib/db.js

@@ -40,3 +40,2 @@ var r = require("rethinkdb");

}
next(err,self);

@@ -47,2 +46,6 @@ });

self.openConnection = function(next){
r.connect(config, next);
};
self.createDb = function(dbName, next){

@@ -49,0 +52,0 @@

2

lib/table.js

@@ -26,3 +26,3 @@ var r = require("rethinkdb");

assert.ok(err === null,err);
self.query(table, criteria,function(err,result){
table.query(criteria,function(err,result){
assert.ok(err === null,err);

@@ -29,0 +29,0 @@ conn.close();

@@ -5,3 +5,3 @@ {

"description": "A light wrapper for RethinkDB",
"version": "0.0.1",
"version": "0.0.2",
"private": false,

@@ -8,0 +8,0 @@ "scripts": {

@@ -18,3 +18,3 @@ # Some Light Abstraction for RethinkDB

```
npm install second-thought --save
npm install secondthought --save
```

@@ -25,15 +25,32 @@

```javascript
var db = require("second-thought").init({db : "test", tables : ['foo', 'bar']});
var db = require("second-thought");
db.connect({db : "test"}, function(err,db){
//you now have access to all of your tables as properties on your db variable:
//so, assume there's a table called "foo" in your db...
db.foo.save({name : "Mike"}, function(err,saved){
//output the generated ID
console.log(saved.id);
});
});
```
The `init` method sets the database name as well as drops the tables on the DB prototype as fields. This is interesting for a number of reasons!
Each table on your DB object is a full-blown RethinkDB table, so you can step outside the abstraction at any point:
Each table that you send into init is a full-blown RethinkDB table, so you can step outisde the abstraction at any point:
```javascript
db.connect(function(err,conn){
db.openConnection(function(err,conn){
//this is a ReQL query
db.foo.eqJoin('bar_id', db.bar).run(conn, function(err,cursor){
//run the joined action
//run the joined action and do something interesting
cursor.toArray(function(err,array){
//use the array...
//be sure to close the connection!
conn.close();
});
});

@@ -48,15 +65,50 @@ });

//installation of the DB and tables
db.install();
//querying
db.query(db.foo, {category : "beer"}, function(err,beers){
//beers is an array, so have at it
db.connect({db : "test"}, function(err, db){
db.install(['foo', 'bar'], function(err,result){
//tables should be installed now...
});
});
db.first(db.bar, {email : "rob@tekpub.com"}, function(err,rob){
//hi Rob
//add a secondary index
db.connect({db : "test"}, function(err,db){
db.foo.index("email", function(err, indexed){
//indexed == true;
});
});
```
db.exists(db.foo, {name : "bill"}, function(err, exists){
//exists will tell you if it's there
## Basic Queries
I've tried to keep the API light and simple - with just a bit of sugar to keep the repetetive stuff to a minimum:
```javascript
db.connect({db : "test", function(err,db){
db.foo.query({category : "beer"}, function(err,beers){
//beers is an array, so have at it
});
db.foo.first({email : "rob@tekpub.com"}, function(err,rob){
//hi Rob
});
db.foo.exists({name : "bill"}, function(err, exists){
//exists will tell you if it's there
});
db.foo.destroy({id : "some-id"}, function(err,destroyed){
//destroyed will be true if something was deleted
});
db.foo.destroyAll(function(err,destroyed){
//destroyed is the count of records whacked
});
db.foo.updateOnly({name : "Stevie"}, "some-id", function(err,result){
//save will do a full swap of the document, updateOnly will partially update
//a document so you need to pass the id along
//result will be true if an update happened
});
});

@@ -66,3 +118,6 @@

Have a look at the tests to see a bit more
## Wanna Help?
Just do me a favor and open a PR with some ideas and hopefully a test or two. Thanks!

@@ -111,2 +111,9 @@ var db = require("../lib/db");

});
it("tells me that Mikey exists", function (done) {
db.foo.exists({name: "Mikey"}, function (err, result) {
result.should.equal(true);
done();
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc