Node package to automatically generate api from database? - javascript

I have a MySQLdatabase that was built for a PHP project. I want to migrate from PHP to Node and use an Express (or similar) API to interact with the database. Is there any node package that can generate the endpoints automatically?

See LoopBack:
https://loopback.io/
On the website:
Set up models and create REST APIs in minutes
Easy-to-use CLI wizard Create models based on your schema if you have
one Create dynamic models if you don't Built-in API Explorer Model
relation support
Define hasMany, belongsTo, hasAndBelongsToMany relationships
Automatically generates corresponding relational REST endpoints
Of course it will not make all of the work for you but it may help.

Related

How to implement row level access control in PostgreSQL using Sequelize?

I am building a multi-tenant backend using Node, Express, PostgreSQL and Sequelize. All of my tenant's data is stored in the same table. Right now, I am using the WHERE clause to filter data and restrict one tenant's data from others but I would like to add another layer of security using the row-level access control feature of PostgreSQL. I found this article very helpful but it does not cover the implementation in NodeJS.

How can I integrate strapi as CMS in my website, meaning i don't want all the backend built with strapi,

I just want the blog part built with strapi the rest is going to be an express backend.
If so how can I implement it ?
Strapi uses node js(koa) and is customizable. you can you express with strapi.
I would recommend you to use strapi and do rest customization in strapi using koa or express(will be a bit complicated).
otherwise you will have to host strapi and use it in your app with the help of rest api.
if you are using one of the following db PostgreSQL, MongoDB, SQLite, MySQL and MariaDB. then for your app as well as strapi you can simply have one database.

How to add a GraphQL server to a pre-existing SQL Database?

I have created a mySQL database at a Host IP, but now wish to use GraphQL to make queries easier from the front-end. I've know how to set up a GraphQL server from scratch, but was unsure how to access my pre-existing tables at the back-end, and where to define the schema to use them. How would I connect to the database from a GraphQL server?
Prisma was an option I considered, but the service doesn't allow connections to mySQL databases which have pre-existing data.
Thanks for the help!
Prisma and other ORMs are a good option if you want a relatively easy/cheap way to expose CRUD operations for your entire database.
If you only need to expose specific aspects of your data or just need to start iterating quickly, you can define your GraphQL API schema at the server level and write resolvers that connect to your database as needed. Your schema does not need to reflect your entire database, but only the data you'd like to expose to clients.
In my experience with GraphQL APIs, I've found that manually writing query schemas and creating resolvers as needed for servicing the client is both faster and easier to maintain for smaller applications.
You can use a SQL client like https://github.com/mysqljs/mysql to interface with your database. The resolvers you write for your schema would then query your database for any data needed to serve the client's request, even if it spans multiple tables.
The GraphQL spec learning site graphql.org has a good description of this process https://graphql.org/learn/execution/#root-fields-resolvers
You can try a new open source tool called SwitchQL (github.com/SwitchQL/SwitchQL). I've been working on the project for a while.
You pass it your connection string and it returns everything you need to run a graphql server on top of an existing database. It also returns Apollo compliant client mutation and queries.
We only support Postgres at the moment. If you end up trying it out, please let me know what you think!

Integrating ExpressJS and MeteorJS

I have an Epress JS rest api that posts values to the mongoDB. I'm wondering if it is possible to integrate Meteor JS to retrieve those values from the MongoDB.
Any thoughts would be appreciated.
Thanks
Meteor's data layer connects to MongoDB, use a normal publish on the server and subscribe from the client. https://www.meteor.com/tutorials/blaze/collections
It won't matter that your Express app updates the db independently - Meteor's reactivity will pick up the changes as they happen.
In meteor for creating REST-API the first choice would be a publish-subscribe call but if you need to make REST-API beyond that you can use 'Restivus' high-level API.
Here is the link

Is it possible to load structure and data to angular-storage(or another storage) from a SQLite file from server?

I think what I'm trying to do is very simple, but I'm having a really bad time trying to search this on the internet. I have this populated sqlite db file in my server, and I want to import its structure and data into my web application. This file is generated from another server-side app in a path which is accessible to the web application.
Your web application should access the database with its proper adapter (depending on the language and the framework) and then provide the data to the front-end as a set of services. It strongly depends on the amount of data and its variability whther you want to serialize all the data at application load time, or just to provide data access using several endpoints (by using the sqlite database as the repository for your application models).
It's not much different from a normal web application, provided you don't want to write on the sqlite database and so consider all your models read-only.

Categories

Resources