API Management - How to connect to a database to query tables - azure-api-management

I'm exploring different options and am looking to use API Management instead of standing up a Web API Service which I could do myself.
I would like to create a database that contains configuration data that gets hidden behind an API.
For example, if the following was defined:
SELECT CountryName, CityName
FROM tblCountry a
INNER JOIN tblCountryCity b ON b.CountryID = a.CountryID
INNER JOIN tblCity c ON c.CityID = b.CityID
WHERE a.CountryID = #countryID
I would like to call some endpoint
https://some_api_managment_service/CountryCity/1
with an associated ID to return the country name and corresponding cities.
Any information or documentation in how to connect the API Management to a database would be appreciated.

as mentioned you'll save a lot of time by using functions (or logic apps).
it is possible to query cosmos via policies. but it is not possible to query azure sql. which repository are you using?

Related

Which will be more efficient for server to handle

Let me say I have a billing program webapp which will serve all users to maintain Thier business.
Eg:
Receipt No, qty, AMT, owner.
Are 4 tupples.
Now when multiple people use same online software, we are identifying transaction of a organisation by owners name.
When he takes his organisation sales report it has filter rows by owner name condition.
So this is delaying the process.
If we make master slaves database
Then we need only 3 Receipt No, qty, AMT, tupples since we can identify organisation by database name.
Which will be more efficient for server to handle !
I also need all organisation reports too combined.
P.S: I am using mysql server for db and web2py platform.

Update a NULL column that was added

I'm not a coder, but from time to time I have to interact with out client database. The company I work for does online education. The problem is that we have two SQL databases
Client_personal
client_educational
Client personal keeps all of the name, email, address, phone type of information. Client educational keeps track of what classes they have purchased. I need to take the information from client educational and tag the client personal information in our CRM. The problem is that the the two databases only have one common field "client id" and my CRM only allows me to search for duplicates by client name. So basically I need to add the client name column to my client educational database. I've added it, but it just says null. Anybody have any advise?
Your question is a little vague but assuming:
They're on the same machine
The table is called clients in both databases
The "client name" field is called clientName in both databases
The "client id" field is called clientID in both databases
You want to copy the data from one table into the other as a one off
You can use a user account with access to both databases
As always please don't run this on your real data. Try a mock first.
something like:
UPDATE client_educational.clients
SET client_educational.clients.clientName = Client_personal.clients.clientName
FROM client_educational.clients
INNER JOIN Client_personal.clients
ON client_educational.clients.clientID = Client_personal.clients.clientID
If you don't actually want to copy data as a one off, you should create a view or use join statements instead.

How to build a "services" BD with prices

Im currently building an interface with PHP and MYSQL with all my salon services and everything was fine till I had to add my waxing services:
When talking about waxing you can have every combination between these group:
Lips
Chin
Face
Underarms
Arms
Eyebrows
None of the above
Also one of these:
Half Leg
Full Leg
No Legs
And one of these:
Small Bikini
Big Bikini
Brasilian
No Bikini
So, I was thinking on doing the first part on binary until I figure out that just on the first part I had 128 combinations, plus 3 different variations on the next group(Legs) and 4 more under the bikini area.... This makes a total of 2048 possible combinations?? so that means that I will have to fill a DB with 2048 different descriptions, prices and services codes(the most important column)
So This is when I know that im doing something wrong here(regarding the method) and I need your help to know how is this done from the BD point of view. After all I just need a service code that will allow me in the future to differentiate each service from the other one.
And if this is the real way of doing it, how or what do you use to generate the 2000+ rows with the data?
Thanks
How would you do this if you weren't using software? If a client came and asked for, say, eyebrows, arms, and full legs....
Would you say eyebrows are $3, arms are $6, and full legs are $10?
If so, you can create yourself a data base row for each particular service you offer, and allow your client to choose any combination of products.
This involves a many-to-many relationship between your client and your service tables. In RDMSs like MySQL, you'll need a client table, a service table, and a client_service table. The third of those contains pairs of numbers, client_id and service_id, and perhaps a date. If you want to know what services a certain client had yesterday, you could, for example, use a query like this
select cs.service_time, c.name, s.service
from client c
join client_service cs ON c. client_id = cs.client_id
join service ON cs.service_id = s.service_id
AND DATE(cs.service_time) = CURDATE() - INTERVAL 1 DAY
where c.name = 'Jane'
The point of the client_service table is to allow you to associate multiple clients with each service, and multiple services with each client. This is a far better software design choice than the combinations you mention, which will soon outnumber the hairs on your clients', umm, heads.
The user interface for this kind of table will present a list of the services you offer (the rows in your service table) with a checkbox next to each one.
As you wait on each client, you'll check the services you deliver. Then your software will create a row in your client_service table for every check on the list.
If your service table contain a price for each service, you can retrieve those prices as follows.
select DATE(cs.service_time), c.name, s.service, SUM(s.price) AS price
from client c
join client_service cs ON c. client_id = cs.client_id
join service ON cs.service_id = s.service_id
AND DATE(cs.service_time) = CURDATE() - INTERVAL 1 DAY
where c.name = 'Jane'
group by c.name, DATE(cs.service_time), s.service WITH ROLLUP

How to check if email exists in two tables using phpmyadmin

I'm trying to export newsletter subscribers from my website.
Using the platforms own export facility, it doesn't export the first name and last name of the subscriber in the same file as the email addresses of the subscribers.
I do have access to the db via phpmyadmin.
In phpmyadmin, I can export the users (90k) in one run, and export the subscribers (18k) in one run, but I don't know how to match them up.
Is there a query I can use to get this done?
I want to search users to see if their email address exists in the subscribers field then to export that out.
The main table is called "site"
And then the fields are:
`site_customers`.`email`
and
`site_newslist_subscription`.`email`
I'm not a programmer and I don't have much experience with querying a db but if someone can help with the correct query I know enough to be able to run it in phpmyadmin.
If anyone can help with this I would be grateful!
I would use a simple LEFT JOIN
SELECT sc.*, sns.`email`
FROM site_customers sc
LEFT JOIN site_newslist_subscription sns
ON sc.email = sns.email
(It would be much faster if email was indexed as that's what we're looking on)

Database Relation source depending on field

I have a database of projects and their parent companies that manage them, each project and company has lists of departaments and countries.
However if project has field DEFAULT set to true, the list of dep/ countries should be loaded from its parent company instead.
My question is what would be the best method to design this ? Is it possible to do it "correctly" in MySQL or should i just manage it in application code (not too good).
You can use a conditional expression in your join criteria. For example, using MySQL's IF() function:
JOIN departments ON departments.departmentID = IF(projects.default,
company_departments.departmentID,
projects_departments.departmentID
)