What is the difference between an API and a database? [closed] - mysql

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 months ago.
Improve this question
I am creating a website and have managed to understand that the frontend is mainly visuals and UI. When I looked into storing the user data (username, passwords, etc.) for my website I see many people mentioning APIs (such as GraphQL) and databases (such as MySQL). I was wondering what the difference between the two are, and how the frontend, API, and database all work in conjunction.

The database is something which store your data. It can be as simple as a text file, but it's not safe, not fast and not concurrent. So you need something, that do the storage for you. This is the database server. It can be a local one, a file-based one, or can be on an other server or on some cloud (AWS, Google). It can be even embedded in the backend server. There are many types to use, the most common is MySQL. You can manipulate the data with SQL languge on an SQL server, or you can use some language specific ORM library to do the manipulation without knowing SQL.
The API means Application Programming Interface. It's something that describe how can you interact with the application (in your case with the backend server). It describe what endpoints (like /users) can be used and what data can be sent and get from any endpoint (URL) from your server. Many backend uses RESTful API, where you can access the most of your data with a CRUD. CRUD means Create, Read, Update, Delete, each one describe in the API, for example:
Create a user:
HTTP POST to /users
Read a user by its Id:
HTTP GET to /users/{id}
Update a user by its Id:
HTTP PATCH to /users/{id}
Delete a user by its Id:
HTTP DELETE to /users/{id}
The API is describe what data and how should be sent and get from an application. It can also describe the ecryption type, the data type (JSON, XML), and so on.

Related

What are the different use cases for using QueryBuilder vs. Repository in TypeORM? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
I'm building an API using NestJS with TypeORM. I've been querying a MySQL database using the TypeORM Repository API mostly because the NestJS Database documentation section provided an example using this.photoRepository.find(). As I get further along, I've noticed many of my exploratory search results recommending using the TypeORM QueryBuilder API for performance and flexibility reasons.
I'm getting the sense that the Repository approach is easier to use for simple needs and a great abstraction if I ever decide to switch my database framework. On the other hand, it also seems to me that QueryBuilder is more performant and customizable.
Could we outline the different use cases for QueryBuilder vs. Repository in TypeORM?
The QueryBuilder API is very powerful and closer to SQL than the Repository API, so anything that is more complex or more SQL driven is more easily done through it. It is your last "tool" before going raw SQL with QueryRunner that you probably don't want to use everytime (as it makes development and refactoring longer).
Even if the repository is easier to do, maybe you don't want your codebase to allow the 2 API to be used as it "splits" the code but it all depends on your team preferences.
The point where the repository API is more friendly is about fetching relations, as eager / lazy relations are parsed from the decorators and you don't have to specify "joins" whereas the QueryBuilder implies you explicit those or it will fetch only the main table (it ignores the decorators, SQL is first citizen).
Anyway, even if you decide to abandon the Repository API or the QueryBuilder API, I recommand strongly that your queries are always easily found in a dedicated class (like a custom repository or a dedicated service) so you don't end up maintaining queries everywhere in your codebase, refactoring data access is dangerous if not controlled. I personally find the "find" method too powerful on Repository API for instance and disallow such API use outside of a dedicated service / class / whatever you decide.

What type of backend to use for iOS app [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I've created an app for iOS using Swift that is essentially a Latin dictionary. Users have the ability to create new words that aren't included in the app. The data is stored locally in the app's document directory in two SQLite databases. The first one holds the words that ship with the app. The second holds the words that are created by the user.
I want to have each word created by the user uploaded to a server at runtime and added to a master database of words. That server would then compare each incoming entry to William Whitaker's Words to see if it is in fact a valid Latin word and then to see if it is already in the master database. If it is valid and not already in the master DB, then the word would be added.
After every new entry to the master database, the server would generate a new SQLite database that includes the new word. Every time the app runs it will check for a newer version of the StandardData.sqlite file and if there is one, it is downloaded. Words that are common to the Standard library and the user's custom library would then be deleted from the custom library to prevent duplicates.
Over time a large library of Latin words would be created without me having to manually enter them in from a dictionary.
I'm somewhat familiar with MySQL (When using it with MySQL workbench) but beyond that I'm mostly unfamiliar with today's web programming tools: HTML5, CSS, JavaScript, Java, Ruby, Rails, PHP, etc. My budget is 0$ and ideally I would like to host the server on my own hardware. What is the best way to add a backend to my app?
This is a question of opinion, so I'm not sure this is the best forum. However you have several options, including some that could be completely free.
Rails and PHP as you have mentioned can be used to create a backend using mysql as the data layer. If you are new to both of those languages, you might look at Python using one of the many frameworks for it. If your app is completely iOS based, you might also look into using CloudKit, which is free up to certain sizes (which it sounds like you could easily stay below). The advantage of CloudKit would be that you don't even have to host the service on your own hardware. There are a few other similar options as well, included Firebase and Parse which both have free tiers that likely would provide all the storage you need.
With any of these three, you'd be using the API in swift in your iOS project, and not having to learn a new language.

Proper way to Include SQL [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am just starting with mySQL, and have been through many of the tutorials, but there are a couple of things I cannot find.
1: Do you just include the following in your HTML, or would it go into a different file (if so, what would the extension be)?
CREATE DATABASE user_db;
CREATE TABLE Users
(
UserNum int,
LastName varchar(100),
FirstName varchar(100),
Address varchar(255),
City varchar(255),
ZipCode varchar(100),
Phone int,
MonthBorn varchar(100),
DayBorn int,
YearBorn int
);
2: How would you create a database used by every page of your website, and never gets deleted (ex. for a user database)?
You can't use mySQL with only HTML. You need to use a server-side scripting language (such as PHP) to do your database work. As for the second question, a database runs on a server where it can be accessed by any page (that is given permission to access it). And the data would persist (never get deleted until you delete it). That's what a database is designed to do. Check out some tutorials on the Google to get a handle on databases.
If you wish to use a database in your web application, then you need to set up and configure the database, in this case. MySQL would be running and you would use commands like that to create the tables within the database. From there, pending on the language(s) your using, you have a plethora of options available for access.
Pretty good guide for using Active Records with Ruby on Rails:
http://guides.rubyonrails.org/active_record_basics.html
Asp.Net has tons of options but works better with SQL Server versus mySQL:
http://www.asp.net/web-forms/tutorials/data-access
You can't interact with a database directly with just html. You'll need to use something like PHP, Ruby, C#, or even javascript on Nodejs to interact with the database. If you wish to do user authentication and management, I suggest starting with a CMS (Content Management System) like WordPress or DotNetNuke. They have plenty of starting out tutorials on how to set up your database, connecting to it and handle user authentication in a fairly secure manner.
To answer both questions, I would look at mysqladmin for actions like creating databases and tables.
http://dev.mysql.com/doc/refman/5.6/en/mysqladmin.html
It's also useful for pretty much anything else you could want to do (testing queries, fixing errors, general maintenence)

Design consideration: One database user connection v.s. multi database user connection [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I used to connect database using one database user per web application.
Now for enterprice application, It seems that multi databse user connection is more safe than one user.
for example: hr dep. use hr db user account in connection and dev dep. use another.
what's the best choice?
You can have one database user account per user, such as "Frank", and "Jane".
You can setup roles as well, such as "HR", or "CSR", and assign your users to roles. You can't do this in MySQL but you can in MariaDB, though you seem to have Oracle too ;)
You would also have a user account for the web server, whose only right is to CONNECT and call SET ROLE. You are essentially delegating authentication to the web server. The web server might authenticate the user in the database, or perhaps using OAUTH.
Connect as the web server user, then call SET ROLE to the name of whichever user is logging in. If you are careful to reset everything in a connection, then you can still use pooling.
Then, a user can only do what you have allowed them for their roles.
This is also useful for auditing, as you can just put CURRENT_USER in an audit table.
If I understand your question correctly, it is generally preferable to set up various accounts so you can define access rights to various tables to the granularity you need.
For example data that belong to HR department should ideally be accessed by employees of the HR while possibly be viewed by higher management. Likewise data regarding customers should be accessed by customer service people etc

iOS Login Screen For External Sqlite Server [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
Ok, so say I wanted to have a sign up form similar to the iOS apps of Facebook, Gmail, Dropbox etc. I don't mean I want to have the users be able to login using those services (although that would be nice) but I want to actually have something similar to a SQL server as the web service https://parse.com/ would use.
It seems like a great service and very easy to setup, but I would like to go the extra mile and take advantage of the servers I have available in the cloud to create my own custom version of the following. I understand that mySQL isn't very usable within the iOS development platform, however sqlite3 is. Say I've created my storyboard layout and I think I have an idea of what it is I would like to do. I just don't know what I need to do to achieve it! Essentially what would be ideal is to to create statistical models based on the combined data from all of the users.
Properties of the application:
I would like the users also to be able to go online and download the data they entered into the iOS app by importing it into excel. However it would be very important that I nor any other user could identify the source of the data. As most of my users are going to know of each other in real life. Think of the app as something to do with drag racing, and the users enter in there race results and information about their setup and then upload it to my server. It is very important that I cannot see which user the information derived from, but at the same time would like to access the data and retrieve a list of the users and their respective emails!
User Interface of application:
Here is a screenshot of what the storyboard ideally might look like. Nothing is linked together yet these are just the screens that I originally had in mind! I'm not asking for anyone to give me any serious help as I want to do it on my own, I just need the resources in order to do it myself. It seems as if there is nothing online that could explain how the website parse's framework was created!
STORYBOARD 1: i39.tinypic.com/fbz7n6.jpg
STORYBOARD 2: i41.tinypic.com/dewoau.jpg
How can I make a service similar to parse (JSON format) by using my own server in the cloud?
You can use MySQL on the server and SQLite on the client (preferably wrapped in Core Data) without any issue. The two shouldn't directly interact or have any knowledge of each other. Because the server will present an API for the client to use. And that API should divulge no information about the internal setup of the server.
For the API, think about a RESTful interface, probably implemented with JSON.
This caters for all of your uploading and downloading capability.
Your other things are built around this. You have good intentions for keeping the data anonymous - but that is a facet of what you send and how you structure the data storage in the server.
Finally, doing it yourself will be error prone and take a long time. Creating a Parse.com account and configuring the database will be relatively error free and will take very little time. What do you make money from? (hint: leveraging the work of others).