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

thinky

Package Overview
Dependencies
Maintainers
1
Versions
129
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

thinky

RethinkDB ORM for Node.js

  • 0.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.3K
decreased by-26.91%
Maintainers
1
Weekly downloads
 
Created
Source

Thinky

JavaScript ORM for RethinkDB.
Note: Alpha release

Quick start

Install:

npm install thinky

Use

var thinky = require('thinky');
thinky.connect({});

// Create a model
var Cat = thinky.createModel('Cat', {name: String}); 

// Create custom methods
Cat.define('hello', function() { console.log("Hello, I'm "+this.name) });

// Create a new object
kitty = new Cat({name: 'Kitty'});
kitty.hello(); // Log "Hello, I'm Kitty
kitty.save(function(err, result) {
    if (err) throw err;
    console.log("Kitty has been saved in the database");
})

Docs

Note: Work in progress.

Thinky

Thinky.connect( options )

options (object): object with the fields

  • host: RethinkDB host (default "localhost")
  • port: RethinkDB port for client (default to 28015)
  • db: default database (default to "test")
  • poolMax: The maximum number of connections in the pool (default to 10)
  • poolMin: The minimum number of connections in the pool (default to 1)
  • enforce: represents if the schemas should be enforced or not. Its value can be:
    • an object with the 3 fields:
      • missing // throw on missing fields // default to false
      • extra // throw if extra fields are provided // default to false
      • type // throw if the type is not the one expected // default to true
    • a boolean that set all 3 parameters to the same value

Note: The behavior of enforce may change. Since there are more than two cases

  • Be flexible
  • Forbid extra fields
  • Forbid missing fields
  • Forbid extra AND missing fields

Thinky.getOptions()

Returns all the options previously set.

Thinky.getOption( optionName )

Returns the value for optionName. Possible values:

- host: RethinkDB host
- port: RethinkDB port for client
- db: default database
- poolMax: The maximum number of connections in the pool
- poolMin: The minimum number of connections in the pool
- enforce: Boolean that represent if the schemas should be enforced or not

Thinky.setOptions( options )

Overwrite the options defined in options.

The argument options is an object that can have the following fields - host: RethinkDB host (default "localhost") - port: RethinkDB port for client (default to 28015) - db: default database (default to "test") - poolMax: The maximum number of connections in the pool (default to 10) - poolMin: The minimum number of connections in the pool (default to 1) Setting a value to null will delete the value.

Note: Almost useless for now since we don't recreate/update the pool

Thinky.disconnect()

Close all the connections.

Thinky.createModel( name, schema, settings ) Create a new model

  • name: name of the model
  • schema: An object which fields can have the following values:
    • String
    • Number
    • Boolean
    • Array
    • Object
  • settings (object): settings for the model
    • enforce: Boolean that represent if the schemas should be enforced or not

Valid schema can be:

{ name: String }
{ name: { type: String } } // {name: "Kitty"} or { name: { type: "Kitty" } }?
{ name: { type: String, default: value/function }
{ name: { type: [String, Number, ...] }
{ age: { type: Number, min: ..., max: ...} }
{ comments: { type: Array, min: ..., max: ...} }
{ arrayOfStrings: [ String ] }
{ arrayOfStrings: [ String, maxLength, minLength ] }

Coming soon: default with object and arrays.

Model

Model.compile( name, schema, settings, thinky )

Internal method

Model.createBasedOnSchema( result, doc, originalDoc, enforce, prefix, schema )

Internal method

Model.checkType( result, doc, originalDoc, schema, key, type, typeOf, prefix, enforce )

Internal method

Model.define( key, method )

Define a method on the model that can be called by any instances of the model.

Model.setSchema( schema )

Change the schema -- Not tested (I think)

Model.getSettings( )

Return the settings of the model.

Model.getDocument( )

Return the document.

Model.getPrimaryKey( )

Return the primary key

Model.save( callback, overwrite )

Save the object in the database. Thinky will call insert or update depending on whether how the object was created.

overwrite: not implemented yet

Model.get( id or [ids], callback )

Retrieve one or more documents

Model.filter( filterFunction )

Retrieve document based on the filter.

Model.count( )

Return the number of element in the table of your model.

Model.mapReduce( filterFunction )

Not yet implemented

Document

Document.getDocument( )

Internal method?

Document.getModel( )

Return the model of the document.

Document.getSettings( )

Document.define( name, method )

Document.replace( newDoc ) Not implemented yet

All method of EventEmitter are available on Document. They do not pollute the document itself.

Internals

When you create a new object from a model, the object has the following chain of prototypes object -> DocumentObject -> Document -> model

Run the tests

mocha

Contribute

You are welcome to do a pull request.

TODO

  • Write the docs
  • Add more complex queries
  • Update pool when poolMax/poolMin changes

About

Author: Michel Tu -- orphee@gmail.com -- www.justonepixel.com

License

Copyright (c) 2013 Michel Tu orphee@gmail.com

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.

Keywords

FAQs

Package last updated on 06 Jul 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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