what is the difference between amazon dynamodb QueryOperationConfig and DynamoDBOperationConfig? and when developer need to use them?
A DynamoDBOperationConfig is part of the object persistence model API:
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DotNetSDKHighLevel.html
A QueryOperationConfig is part of the document model API:
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DotNetSDKMidLevel.html
They both can perform all of the DynamoDB API calls, they are just different APIs for interacting with the service. The object persistence model is great for saving/loading objects of the same type. The document model allows you to serialize native .NET JSON types to DynamoDB types seamlessly.
Related
I want to build an app where I have an Entity of Type A. This Entity class should have an update method which then uses 3rd party modules for example to fetch data from a 3rd party api and so on.
I am kind of lost on how to do that, if its even possible to. Basically I want the Entities to be able to perform function calls just like normal es6 classes.
Until now I always used a service that updates all entities, I prefer all Entities to handle their own updates tho.
Basically can the enities I define which also get stored to database have async functions I could then just call on the object after retrieving it from the database? Is there a constructor call once these entities get fetched via find() methods of the repositories?
I pretty much want to avoid having an Entity of type A and also a class implementation for type A just to perform stuff and use 3rd party modules. Until now I used to create the Model, fetch the Models from the database and than instantiate Objects (Classes) that represent these models which is kind of verbose to me.
In a typical MEAN stack application, the server side have Model, View and Controller, where the Model represents the mongoose model. Suppose that, the application does not access to database directly, rather it is accessing the database via RESTful API, is there any model representation in this case? If yes, what is the model representation?
There are various processes which run sequentially when we do some kind of operation using mongoose. Calling statics, methods, data validations, pre-save hooks are some of them. Now, for a REST API accessing DB there are ways to create these processes.
Let's say we are doing operations on users -
Create a service which can validate all the data of a particular user (req.body) using a validator such as validator.js
Create methods in that service which can serve as statics or methods same as they are created in a mongoose model
You can also create pre-save hooks (method which is always called, like hashing password) if necessary before sending your data through the REST API
It is possible to create multiple services to validate and modify data as and when necessary in a very nice way by calling them in an order at your route middleware.
For example -
router.post('/users', [
RestService.getUserById,
UserService.checkForDuplicateUser,
UserService.validateData,
UserService.preSaveHook,
RestService.saveUser
]);
So in this way a model representation can be created.
I am developing a Nodejs application and my database is Postgres and I am using Sequelize as my ORM because of its excellent support for migrations.
I am on the lookout for a good REST API generator based on the schema I have defined. There are two main hurdles I am facing and they are that the generators don't do a good job of creating association API routes and lack of ACL support.
On the associations front, my schema has multiple levels of association i.e. for example..
Student.hasMany(Courses);
Courses.hasMany(Subjects);
So ideally the generated REST API should be something like
/student/:student_id/course/:course_id/subject/:subjectId
I found a few projects that are doing this, but are incomplete.
https://github.com/sequelize/sequelize-restful - is good but does not have ACL support
https://www.npmjs.org/package/restizr - is in alpha stage and does not generate API routes for associations.
Is there any module that supports this?
What you were doing here is writing a webservice without a domain model. https://en.wikipedia.org/wiki/Anemic_domain_model Ofc. you have every right to do it, but I wonder if you really understood what a webservice means. https://stackoverflow.com/a/1530607/607033 It is not a database with CRUD HTTP interface normally, though nowadays it is popular doing something this way and call it REST. A response to a REST HTTP request is a viewmodel https://softwareengineering.stackexchange.com/a/425001/65755 and it contains not just data, but a lot of metadata and hyperlinks. A REST API is a special type of webservice with many constraints. https://www.ics.uci.edu/~fielding/pubs/dissertation/fielding_dissertation.pdf http://www.markus-lanthaler.com/research/hydra-a-vocabulary-for-hypermedia-driven-web-apis.pdf Your ORM is used 2 layers deeper in the data layer and it has nothing to do with the presentation layer where your REST API should be. I really wonder why people are making applications, which are doing nothing except serving data directly from the database and use the most inconvenient technology to do it. I guess there are databases nowadays with ACL and REST API support, so all you need is just using them. https://learn.microsoft.com/en-us/rest/api/sql/ Or there was something for PgSQL and Nodejs too around the time you asked this. https://github.com/QBisConsult/psql-api
I want to write a service method using ServiceStack (c#) and ServiceStack.OrmLite to save the dynamic objects, sent by client (in parameter), in a SQL Database. Also, this method will first create the table in database for this dynamic object. Service will be unable to recognize the class type of the object to be persisted as it will only be defined on client side.
I have explored OrmLite a bit and found that it has DatabaseTableConfig and DatabaseFieldConfig classes to persist an object with unknown type. Unfortunately I am unable to find these classes in ServiceStack.OrmLite library.
Any help in the coding strategy?
The Java OrmLite and the ServiceStack.OrmLite are not the same and as such the classes you refer to do not exist in ServiceStack.OrmLite.
Service will be unable to recognize the class type of the object to be persisted
As you are creating dynamic objects which you can't type, then an ORM (Object-relational mapping) is probably not the way to go, as ORM is all about using typed data.
The best approach would be to build the SQL queries yourself, and use a SqlCommand.
I'm building an app using express and mongoose. My backend is an api (since the frontend is native iOS). In an MVC framework, the controller acts as an interface between Model and View. Since I don't have Views, should I do away with the Controllers and keep my crud operations in the Models, or should I keep them in the Controllers? What are the pros and cons of each approach?
View
You still have a view since you'll need to display whatever the response is.
CRUD operations
These operations are delegated to the service layer by controllers. The service layer alters the state of the model layer.