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.
Related
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!
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.
I want to create a website that queries and inserts data to and from my configured SQL Database. I have not been able to write any code yet because I can't find any reference or documentation for Javascript.
If you are looking for any solution about querying data against SQL Database from browser in javascript, I strongly don't recommend it. Because everyone browsing your website, can find your SQL Database's connection info. And your SQL Database will be exposed to public.
I recommend you to build a backend application for querying data from your SQL Database, and provides the data to your front website.
For more info about how to use the backend languages to connect to SQL Database, please refer to https://azure.microsoft.com/en-us/documentation/articles/sql-database-develop-nodejs-simple/.
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.
Im just starting out using Azure and i have minimal experience with SQL, so I'm a little confused. I set up my Azure Webapp to pull from a Git repository on bitbucket. I successfully linked those two together, and pushes made to bitbucket update my site. What I am having trouble doing is linking my database on Azure to this site, so that I can make data entry forms and insert that info as records onto this database. Im just starting out simple to learn the basics. I have a table names Users with the elements, id(which is set up as IDENTITY so it sequentially creates a unique id number), username, password, and email. I can pull the info from the HTML document and everything just fine, but how do I correctly link my DB and its tables using HTML, js, and azure? Ill post any additional info that will be necessary, i dont even know where to begin on this really.
Ill also add im using Visual Studio for creating tables and entities and most DB management.
Thanks in advance.
How to access your database depends on the database you are using and the server side programming language. From the tags you used in your question I assume you are using the mysql database provided by clear db through the Azure Management Portal. You can not access your database right from JS. As you are using VS I guess you are using asp.net on the server side. If using asp.net this article might help: https://msdn.microsoft.com/en-us/library/ms178371%28v=vs.100%29.aspx
If you created a ms sql database through the SQL Database service in MS Azure you also need to check the firewall settings to allow access from your app.