Is it possible to access an SQL database migrated using Django with a JavaScript ORM instead of raw SQL for a microservice architecture? - sql

Suppose that I have an app where the models have been created using Django ORM and Django acts like an API for authentication and gives control to the relation model User using its ORM. At the same time, we want to use Express JS to continuously update a field in one the User model for some feature that requires performance. Is it possible to use a JavaScript ORM with Express JS to update such field? If yes, then how?

In the following tutorial tutorial for Golang, the database is created using SQL and a table called go_test_model is created. Then he uses the struct called GoTestModel to create a row in the table go_test_model.
This basically means that if we create an app called api in Django and add in it a model called Example, then to handle that model in Golang we just create a struct called ApiExample and from there we can have CRUD access to the same table, there might be some conflicts in the fields datatypes between GORM and Django ORM but integrity is still applied in the database itself.
So this particular example solves my problem with Golang and can be replicated using Node JS.

You can use Sequelize for using native functions for performing queries instead of writing raw queries.
Also, please refer to Models section to define models.

Related

How to force creation of OpenIddict tables in not empty DB

Does anybody know whether there is a way to use default OpenIddict storage functionality in a project which doesn't use Entity Framework and has not empty DB?
I'm trying to integrate Openiddict server to my Web App. The app has a DB, but communication with it is done using classic ADO.Net. I tried to find a similar example in the openiddict-samples repository but unfortunately without result.
I know that I can implement my own TokenStore, ApplicationStore etc. and register them via extensions for OpenIddictCoreBuilder but I'd like to use the default implementations in case it's possible to do that with not empty DB and without EF or with EF but for Openiddict functionality only. My DB is quite big and it's not an easy task to migrate it to EF.
I tried to use code from existing examples but those didn't work in my case. What I found out is that it works with empty DB only, otherwise OpenIddict tables are not created.
So I would very appreciate for any advice or link to example which I should investigate more carefully. So to say make OpenIddict to create its tables automatically, under the hood.
P.S.: I of course can copy those tables from examples and include scripts for their creation in my app, but I'd like to use the built-in functionality as much as possible.
OpenIddict version: 3.1.1
It seems that for now there is no a built-in functionality to achieve the wanted behavior. The only way is to create own Stores and StoreResolvers for OpenIddict and migrate tables creation to any suitable solution: a set of sql scripts, some kind of migration (e.g. FluentMigration), etc.
For now OpenIddict out of the box supports EF and Mongo only. This implementations can be considered as examples for implementation of Stores and StoreResolvers.

Best method for using stored procedures and table valued functions in ASP.NET Core 5

We are developing a razor application with VueJS on the frontend and razor / ASP.NET Core 5 on the backend. VueJS accesses the data via post (ajax) requests which we are handling using page handlers in the page models.
I have integrated Entity Framework and done a few queries for practice however I am realizing Entity Framework is not my answer. All of my SQL queries are saved as table valued functions in SQL Server and the update / insert / delete operations are done using stored procedures in SQL Server.
We have a SQL programmer so he just does everything server-side to keep things simple and just gives us function / procedure names and parameters.
I like this approach and we used this in our application when it was VBA in Excel using ADO and recordsets but now that we are using ASP.NET Core in a web setting so I am learning Entity Framework. However EF requires me to maintain models and that seems unnecessarily complicated as my SQL results are generated from procedures / functions.
Really I just need to run these procedures / functions and return the results as a json data array in the POST request.
What would be the best option for this in regards to performance and simplicity (hopefully they can go hand in hand)? A simple code example would also be helpful to get the ball rolling.
As for other questions on StackOverflow I have seen one question which is similar that says dapper is great for stored procedures but does not indicate if table valued functions are allowable.
Please note that Entity Framework Core also allows us to execute raw SQL query to make use of existing stored procedure. For more information about executing raw SQL queries with Entity Framework Core, you can check this doc:
https://learn.microsoft.com/en-us/ef/core/querying/raw-sql
Besides, if you want to implement it with ADO.NET approach, you can try to use Microsoft.Data.SqlClient that provides the data provider for Microsoft SQL Server.
https://devblogs.microsoft.com/dotnet/introducing-the-new-microsoftdatasqlclient/

Creating a model in nodejs without an ORM or ODM

I am surprised why this is so hard to find.
I am trying to convert my monolith to a 3 layer architecture for my node express app with a propriety sql.
Repository
BEFORE architecture change
1 file entry.js
1 endpoint with business logic
Functions with raw sql that are called after validation of res.body objects
AFTER
📁 backend
📁 src
📁 services
📄 service1
📁 routes
📄 service1Route [ Route handling /service1 from entry.js ]
📁 models
-service1Model [ Contains sql functions, not schema ]
📄 entry.js [ Main express app]
Tech used
- Using .js not .ts
- nodejs
- express
-
Constraints
- I cannot use postgres or sequlize as they don't support the propriety db that I am using.
Assumptions
postgres or mongoose have popular ORMs and ODMs without which you cannot use them hence developers are ( as a good practice ) forced to create models.
Now I want to create my own models / schema with such validations.
Ask
How do I create models without ORM or ODM.
Is there a difference between schema and model ?
Writing sql functions in model folder : is that the right way to use this architectural pattern.
If schema/model is created in 📁 models folder then where do the sql queries reside ?
What I have tried?
For validating objects with required keys from res.body object
I'll have a go at answering. I'm a database engineer and have written node.js apps that connect directly to the database without using an ORM.
1: So long as you know the structure of the data that you wish to store as it resides in the database you can write a javascript class that has methods to do all of your updating and class instantiation etc. For instance, you can have a user class with a constructor and a number of methods for creating a new user in the database, retrieving a user from the database, updating a user etc. You can read more about javascript classes here and here.
So here your Model is just a class that knows how to interact with the database.
You could store all of your SQL here, but I would advise against that in favour of using Stored Procedures in the database. That way if you ever need to tune your query, or make changes, you can change just the stored procedure without having to create a whole release of your application. Your DBAs can also tinker round with your SPs for you as well.
2: Depends what you're referring to here. A schema in the database is a container for functionality, business areas, or whole applications. Like within a business you could have a Sales schema and a Marketing schema, or you could store all of your application logic in the MySalesApp schema.
A javascript model is one particular piece of functionality and its interactions with the database. Like a user, or a person, or an animal etc. In the database all of these objects (there would probably be a person/user/animal table, with a number of stored procedures for updating, creating, etc) would be stored inside a schema. In MySQL a schema can also be a whole database.
3: You could store your SQL there. But for the reasons mentioned before I'd do this with Stored Procedures. Basically because you can tune them for efficiency without having to redeploy your whole application.
4: This also answered by using Stored Procedures. So instead of having a bunch of code that creates a user, you have an SP that lives in the database and handles everything for you. Then you just end up with a call to a stored procedure that looks like this:
var query = "BB.sp_CreateUser";
var params = [
parseInt(user.userId),
user.firstName,
user.surname,
user.userInitials,
user.telephone,
user.username,
user.password
];
let result = await database.asyncQueryDynamic(query, params);
I've got a bit of abstraction going on here because I'm using connection pools etc. But you can read more about using Stored Procedures here.

create databases and tables dynamically with Yii framework possible?

I am developing a system with a master database and multiple databases, once for each client. The client database and its tables will be created when the client fills in and submit a form with all the required details.
My question: does the Yii framework support the dynamic creation of databases and tables? If so, is there any example code? (I'm still learning about Yii) I couldnt find an answer on the Yii website (documentation and forum) nor on this site. (I did notice that dynamic databse connections are possibble with Yii - Yii Dynamic DB Connection according to user?)
For connections in runtime read php-yii-database-connect-in-runtime and after that, Yii have all Building Schema Manipulation Queries like CREATE, ALTER, DROP etc.
So easy and simple.
building-schema-manipulation-queries

Execute complex query using Session (coldfusion.air.session class)

We are working on a sync application using ColdFusion 9.0.1 ActionScript ORM Library for AIR applications. Since this is application should work smoothly offline as well, there is a list of clients that has to be loaded when a user logs in, hence we are fetching data from all the required tables when application loads (is that the right way?). Now when we get the data from the required tables then based on the user who logs in we have to filter the clients, to filter this the query required is a complex one with joins between 5-6 tables and where clause. What I found that using the Coldfusion.Air.Session class we can only load objects of tables with simple where clause. There is non ORM way to load the data but I don't think that is the right method. Is there any method using this ORM framework to load data using such complex queries.
Thanks,
Gaurav
Are you using any CF code to send data back to your application? Have you tried HQL?
In other words you can write standard cfquery and dbtype="hql"
This will let you do almost anything you can do with a standard cfquery.
I am not directly familiar with the ActionScript ORM Library for AIR.