How to use the dynamoose.model function in dynamoose

To help you get started, we’ve selected a few dynamoose examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dynamoosejs / dynamoose / manual_test / index.js View on Github external
const sdk = dynamoose.aws.sdk; // require("aws-sdk");
sdk.config.update({
	"accessKeyId": "AKID",
	"secretAccessKey": "SECRET",
	"region": "us-east-1"
});
const ddb = new dynamoose.aws.sdk.DynamoDB({"endpoint": "http://localhost:8000"});
dynamoose.aws.ddb.set(ddb);
dynamooseOld.setDDB(ddb);

const Cat = dynamooseOld.model("Cat200", {"id": Number, "name": String, "breed": String}, {"create": false});
const CatB = new dynamoose.model("Cat200", {"id": Number, "name": String, "breed": String}, {"create": false});

async function main() {
	// const cat = new Cat({"id": 10, "other": "Test", "name": "test"});
	// console.log(cat);
	// const other = await cat.save();
	// console.log(other);
	// console.log(await Cat.get(10));

	// for (let i = 0; i < 1000; i++) {
	// 	const cat = new CatB({"id": i, "name": new Array(50000).fill("a").join("")});
	// 	await cat.save();
	// }

	// console.log((await CatB.scan({breed: {contains: 'Terrier'}}).exec()));
	// console.log(await Cat.scan({breed: {contains: 'Terrier'}}).exec());
github ctindel / reader / social-auth-example / backend / dynamoose.js View on Github external
UserSchema.statics.upsertCognitoUser = function(email, fullName, password, cb) {
        var UserModel = dynamoose.model('User', UserSchema, {create: true, waitForActive: true});
        var attributeList = [];
        attributeList.push(new AmazonCognitoIdentity.CognitoUserAttribute({Name:"email",Value:email}));
        attributeList.push(new AmazonCognitoIdentity.CognitoUserAttribute({Name:"name",Value:fullName}));

        userPool.signUp(email, password, attributeList, null, function(err, result){
            if (err) {
                console.log("Error with userPool.signUp");
                console.log(err);
                return cb(err, result);
            }
            // console.dir(result);
            var cognitoUser = result.user;
            console.log('user id ' + result.userSub);

            var newUser = new UserModel({
                fullName: fullName,
github ctindel / reader / social-auth-example / backend / dynamoose.js View on Github external
UserSchema.statics.upsertFbUser = function(accessToken, refreshToken, profile, cb) {
        var UserModel = dynamoose.model('User', UserSchema, {create: true, waitForActive: true});
        UserModel.queryOne('email').eq(profile.emails[0].value).exec(
            function(err, user) {
                if (!user) {
                    // no user was found, lets create a new one
                    console.log("No existing user was found with email " + profile.emails[0].value)
                    var newUser = new UserModel({
                        fullName: profile.displayName,
                        email: profile.emails[0].value,
                        facebookProvider: {
                            id: profile.id,
                            token: accessToken
                        }
                    });

                    newUser.create(function(error, savedUser) {
                        if (error) {
github novemberde / serverless-todo-demo / serverless-api / routes / todo.js View on Github external
const router = require("express").Router();
const dynamoose = require('dynamoose');
const _ = require('lodash');

dynamoose.AWS.config.region = process.env.AWS_REGION;
const Todo = dynamoose.model('Todo', {
    userId: {
        type: String,
        hashKey: true
    }, 
    createdAt: {
        type: String,
        rangeKey: true
    },
    updatedAt: String,
    title: String,
    content: String
}, {
    create: false, // Create a table if not exist,
});

router.get("/", (req, res, next) => {
github novemberde / serverless-crawler-demo / handler.js View on Github external
const got = require('got');
const cheerio = require('cheerio');
const dynamoose = require('dynamoose');

require('aws-sdk').config.region = "ap-northeast-2";

const PortalKeyword = dynamoose.model('PortalKeyword', {
    portal: {
        type: String,
        hashKey: true
    },
    createdAt: {
        type: String,
        rangeKey: true
    },
	keywords: {
		type: Array
	}
}, {
    create: false, // Create a table if not exist,
});

exports.crawler = async function (event, context, callback) {
github ctindel / reader / social-auth-example / backend / dynamoose.js View on Github external
email: email,
                cognitoProvider: {
                    id: result.userSub
                }
            });

            newUser.save(function(error, savedUser) {
                if (error) {
                    console.log(error);
                }
                return cb(error, savedUser);
            });
        });
    };

    dynamoose.model('User', UserSchema, {create: true, waitForActive: true});

    return dynamoose;
};
github ctindel / reader / social-auth-example / backend / routes / user.js View on Github external
'use strict';

const express = require('express');
const router = express.Router();

const MIN_PASSWORD_LENGTH = 8;

var _ = require('lodash');
var validator = require('validator');
var _UserModel = require('dynamoose').model('User');
var _logger = null;

function checkAuthentication(req,res,next){
    if(req.isAuthenticated()){
        //req.isAuthenticated() will return true if user is logged in
        console.log("SUCCESS: req has authentication")
        next();
    } else{
        console.log("ERROR: req has no authentication")
        res.redirect("/login");
    }
}

module.exports.addUserAPIRouter = function(app) {
    var router = express.Router();
github lucianopf / bitwages / lib / db.js View on Github external
const dynamoose = require('dynamoose')
const dynamoURL = process.env.dynamoURL || 'defaultDynamoDbUrl'

dynamoose.AWS.config.update({
  accessKeyId: process.env.accessKeyId || 'defaultKey',
  secretAccessKey: process.env.secretAccessKey || 'defaultKey',
  region: process.env.region || 'defaultKey'
})
dynamoose.local(dynamoURL)

const Api = dynamoose.model('api', {
  id: {
    type: Number,
    hashKey: true,
    index: true
  },
  timestamp: {
    type: Date,
    index: true
  },
  PricesSummary: Array,
  percentageOverBitwage: Array,
  USDBRL: Array,
  USDBRLACTIVEACTION: Array,
  USDBRLPASSIVEACTION: Array,
  sourceValues: Object
})
github ctindel / reader / social-auth-example / backend / passport.js View on Github external
'use strict';

require('./dynamoose')();
var passport = require('passport');
var TwitterTokenStrategy = require('passport-twitter-token');
var User = require('dynamoose').model('User');
var FacebookTokenStrategy = require('passport-facebook-token');
var GoogleTokenStrategy = require('passport-google-token').Strategy;
var CognitoStrategy = require('passport-cognito')
var config = require('./config');

module.exports = function () {

    passport.use(new TwitterTokenStrategy({
            consumerKey: config.twitterAuth.consumerKey,
            consumerSecret: config.twitterAuth.consumerSecret,
            includeEmail: true
        },
        function (token, tokenSecret, profile, done) {
            User.upsertTwitterUser(token, tokenSecret, profile, function(err, user) {
                return done(err, user);
            });

dynamoose

Dynamoose is a modeling tool for Amazon's DynamoDB (inspired by Mongoose)

Unlicense
Latest version published 2 months ago

Package Health Score

95 / 100
Full package analysis