Comments (10)
are you able to share how you are doing it?
Following the example, you only need call the createTables once.
After which, you shouldn't need to call it again for every other CRUD methods.
from dynogels.
Yes sure
var dynogels = require('dynogels');
var Joi = require('joi');
dynogels.AWS.config.update({
accessKeyId: 'accessKeyId',
secretAccessKey: 'secretAccessKey',
region: 'region'
});
var userModel = dynogels.define('user', {
hashKey: 'id',
timestamps: true,
schema: {
id: dynogels.types.uuid(),
name: Joi.string(),
email: Joi.string().email(),
rating: Joi.number()
},
indexes: [{
hashKey: 'id',
rangeKey: 'name',
name: 'UserNameIndex',
type: 'global'
},
{
hashKey: 'id',
rangeKey: 'email',
name: 'UserEmailIndex',
type: 'global'
}]
});
dynogels.createTables({
'user': {readCapacity: 1, writeCapacity: 1}
}, function(err) {
if (err) { return err; }
});
module.exports = userModel;
from dynogels.
hey @rahulkulmi
the code looks fine, but how are you calling the createTables
, dynogels.define
and the CRUD?
A trimmed down version of what I have in my project is on app start, I would define all the models before calling the createTables(...)
.
At which, I could then call the CRUD methods against the model.
Take note: all these are done against the same dynogel instant
eg. (sorry my code is in ES6, but i'm sure you can convert it to match ES5)
import dynogelWrapper from './DynogelsWrapper'
import userModel from './UserModel`
import accountModel from './AccountModel'
dynogelsWrapper.createTables(...)
dynogelWrapper is basically
import dynogels from 'dynogels'
dynogels.AWS.config.update({
accessKeyId: 'accessKeyId',
secretAccessKey: 'secretAccessKey',
region: 'region'
});
class DynamoPersistent {
defineSchema(tableName, tableSchema){
dynogels.define(tableName, tableSchema)
}
createTables(){
dynogels.createTables(...)
}
}
export default const dynogelWrapper = new DynamoPersistent()
As for the UserModel
, it is pretty much what you have.
Except that you would import the same dynogelWrapper
and then calling the defineSchema
method.
If you are interested in a proper Data Access Layer where it is designed for scalability, then I recommend that you check out other repositories for more examples. My example is by all mean as an example to get you going and not something you would build for production.
Best of luck and happy hacking.
from dynogels.
@M1chaelTran Thanks for give me good solution.
I am working on aws lambda function and my project is based on server less framework. Here I don't find a way to perform some operation before app start because in lambda function there is no app start that is why I have to keep createTables inside the model.
So if you know how to do dynogel wrapper in lambda function so please let me know.
from dynogels.
oh, you should have mentioned that from the start!
i too have a few lambda functions working with dynomodb triggers and schedule tasks.
a few questions you might like to ask yourself are:
- do you really need an ORM (like dynogel) in your lambda? (because you can just call direct to dynamodb SDK provided by AWS)
- do you really want to create a table each time the lambda function run? (most of my cases, the table already exist, and all i needed to do is CRUD operations on it)
- if you still need to create the table every time and still wanted to use ORM in your lambda, then you going to expect a performance hit.
Keeping in mind that when you create a table with global secondary indexes, it going to take even longer time, which we all know that is an issue when it comes to lambda.
from dynogels.
- Yes I need dynogel ORM
- No (only when if table is not there) I am also using CRUD operation only
- No I don't wanted to create table every time using dynogel
from dynogels.
My recommendation is to not use the dynogels createTables mechanism as part of your application start process. Due to the slow deployment of these tables your application can start very slowly. We've moved our create tables script to our CI build process and now don't need to worry about the tables being there at application runtime. I'd heavily recommend not using the createTables method in a lambda function.
from dynogels.
@rahulkulmi do u still have to use createtable for simple crud if you already have tables on dynamodb? im working on lambda as well
from dynogels.
@wuichen YES i am still using createTables for CRUD if already have tables on dynamodb.
from dynogels.
@rahulkulmi I would instead suggest having a Lambda function that only calls createTables, and have your build/CI system invoke this function after deploying any commits that change the model schemas.
from dynogels.
Related Issues (20)
- Does not enforce required() on nested property HOT 6
- What is the best way to convert a list of objects HOT 1
- Provide access to the AWS request object
- Model.validate not in latest release HOT 1
- Add transactions support HOT 1
- A method which returns the raw DynamoDB params for creating an item
- When I do an .updateAsync() with ReturnValues I recieve a type error
- Item.set doesn't work as advertised HOT 3
- Security question?
- while updating the model getting validationException HOT 1
- Project is dead? HOT 27
- using reserved word in schema causes silent error
- Enable On-Demand Billing Mode
- Cannot use "startKey" when using an index HOT 1
- 'updatedAt' field doesn't change once set.
- ValidationException on .destroy() method HOT 3
- Update joi dependency to use @hapi/joi HOT 6
- Keep getting Error: Invalid schema content when I use define HOT 3
- Stale library? HOT 1
- Is it possible to run dynogels with version 3 of AWS
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dynogels.