Search / Filter problems - database

I have a database that stores a range of email addresses, i also have a table consisting of all of the approved addresses. the search i am looking to complete is one where when i run the approved member query and its returns all of the members that have an email address already approved by the database. i have set up a provider column this i though would be best to link these through for example:
if i have hotmail.com and aol.com authorised
when i run the query it will return all emails ending with these providers. a basic filter could work but i have hundreds of approved emails. so im asking is there anyway to search through the entire column of the approved list?

How about:
SELECT Email FROM Table
WHERE Email IN (Select Email FROM ApprovedTable)

Related

Google Data Studio: Filter report data through parameter in URL

I have a Google sheet where each row contains data for a single person.
First column is an alphanumeric random id.
Is there any way I can build a personal score card report which I can share with each person through a link?
The link would contain a parameter for filtering the datasource by the id column. I mean sharing by sending links via email, for example:
Send an email to John with the following link: <url>?id=kfdjfhdfljdshfsdkj
Send an email to Mark with the following link: <url>?id=fdyfdhfsfjsdkjfksd ….
I have thought about adding a filter control plus enabling bookmark urls, but would like to avoid that as that would be a possible security breach. Other ideas?
Thanks
If you can put your data in BigQuery, an alternative approach is to use authorised views. It is explained in details in How To Control Access To BigQuery At Row Level With Groups
The filter based on the email address feature can be implemented by adding an email address field alongside the existing field(s), such as alphanumeric random id in the Google Sheet.
Once that's done, connect the Google Sheets Data Source to Google Data Studio, and then at the Data Source, filter based on the email address of the respective user ID (filter located on the upper left of the Data Source section).

Query MongoDB to find array that contains elements from another array

For my users table, each user has an emails<Array> property allowing them to associate multiple emails with their accounts. I want to make sure this is still unique so wether they're creating a new account or updating existing I need to query the DB to identify if that email address exists.
I know I can use users.find({ emails: email }) and could loop over that to identify, then check the _id (on update) to ensure everything but that puts me in a loop outside the query.
I'm curious if there's a method I'm not seeing for querying to identify if any emails being submitted match any emails from across the table in the db?

SSIS - do not allow if

I have an employee table with both Active and Terminated employees, one of my columns is work email. Terminated employees should have their personal emails listed and Active employees should have their work emails listed. However, the source system I am pulling the information from allows active employees to update their work email. So I have some active employees with their personal emails listed.
For my purposes, I need all active employees to have their work email listed. In SSIS, what would be the best approach to solving my issue?
Ex:
Name Status Email
Bob Act bob#workdomain.com
Joey Ter joey234#yahoo.com
Randy Act randy23#hotmail.com
Here, since Randy is as Active employee should have an email ending with #workdomain.com but, in the source system I pulled data from Randy changed his email to be his personal. Randy's email should be: randy#workdomain.com
I would have done like below (to avoid OLEDB transformation - row by row operation).
Load the data to 2 Staging tables (may be temporary tables):
Table#1. StageEmp:
Name Status Email
Bob Act bob#workdomain.com
Joey Ter joey234#yahoo.com
Randy Act randy23#hotmail.com
Table#2: CorrectEmail
Name Email
Randy randy23#hotmail.com
In Execute SQL Task:
Update s
SET s.email = c.email
FROM StageEmp s
Join CorrectEmail c
ON s.Name = c.Name
where s.status = 'Act'
AND s.email not like '%#workdomain.com'
You should use key column in place of Name.
Load the data of StageEmp to actual table or update directly to the actual table.
According to me, you have one Data Flow Task under which you have one Excel Source to fetch data from excel file. You can do this way -
1. Add one "Lookup" component and pass output of "Excel source" to it.
2. Edit "Lookup" component, and add second source of input to it from your existing table (where you have work email).
3. Join these two inputs to "Lookup" component on the basis of one of the key columns,
so that in output you have two columns one email column from source and one email column from destination.
3. Add "Derived column" component and pass output of "Lookup" to it.
4. Edit "Derived Column", add new column and add expression to check whether email column has "#work-domain" or not.
If yes, then source email else destination email.
Hope so i am able to explain.

Model datastore application

I am looking how to create an efficient model which will satisfy the requirements I put below. I have tried using gcloud-node but have noticed it has limitations with read consistencies, references, etc. I would prefer to write this is nodejs, but would be open to writing in java or python as long as it would improve my model. I am building around the new pricing model which will come July 1st.
My application consists of a closed email system. In essence what happens is users register to the site. These user's can make friends. Then they can send emails to each other.
Components of the app:
Users - Unlimited amount of users can join.
Friends - A User can have 200 confirmed friends and 100 pending friend requests. When a friendlist is retrieved it should show the name of the friend. (I will also need to receive the id of the friends so I can use it on my client side to create emails).
Emails - Users can send emails to their friends and they can receive emails from their friends. The user can then view all their sent emails independently(sentbox) and all their received emails independently(inbox).
They can also view the the emails sent between themselves and a friend order by newest. The emails should show the senders and receivers names. Once an email is read it needs to be marked as read.
My model looks something like this, but as you can see their are inefficiencies.
Datastore Kinds:
USER
-email (id) //The email doesn't need to be the id, but I need to be able to retrieve users by their email
-hash_password
-name
-account_status
-created_date
FRIEND
-id (auto-generated)
-friend1
-friend2
-status
EMAIL
-id (auto-generated)
-from
-to
-mutual_id
-message
-created_date
-has_seen
Procedures of the application:
Register - Get operation to see if a user with this email exists. If does not insert key.
Login - Get operation to get user based on email. If exists retrieve the hash_password from the entity and compare to user's input.
Send friend request - Friend data will be written twice for every relationship. Then using the index on friend1 and index on status I will query all the friends for a user and filter only those which are 'pending'. I will then count these friends and see if they are over X. Again I will do this for the other user. If they are both not over the pending limit, I will insert the friend request. This needs to run in a transaction.
Accept a friend request - Friend data will be written twice for every relationship. Then using the index on friend1 and index on status I will query all the friends for a user and filter only those which are pending. I will then count these friends and see if they are over X. Again I will do this for the other user. If they are both not over the pending limit, I will change both entities's status to accepted as a transaction.
Show confirmed friends - Friend data will be written twice for every relationship. Then using the index on friend1 and index on status I will query all the friends for a user and filter only those which are accepted. Not sure how I will show the friend's names (e.g what happens if a user changed their name this needs to be reflected in all friend relationships and emails!).
Show pending friends - Friend data will be written twice for every relationship. Then using the index on friend1 and index on status I will query all the friends for a user and filter only those which are pending. Not sure how I will show the friend's names (e.g what happens if a user changed their name this needs to be reflected in all friend relationships and emails!).
View sent emails - Using the index on the from property I would query to get all the sent emails from a user 5 at a time ordered by created_date (newest first). (e.g what happens if a user changed their name this needs to be reflected in all friend relationships and emails!).
View received emails - Using the index on the to property I would query to get all the received emails to a user 5 at a time ordered by created_date (newest first). When a emails is seen it will update that entities has_seen property to true. (e.g what happens if a user changed their name this needs to be reflected in all friend relationships and emails!).
View emails between 2 users - Using the index on mutual_id which is based on [lower_lexicographic_email]:[higher_lexicographic_email] to query the mutual emails. Ordered by newest, 5 at a time. (e.g what happens if a user changed their name this needs to be reflected in all friend relationships and emails!).
Create email - Using the friend1 and status index I will confirm the user's are friends. If they are friends, I will insert an email.

Block list table (IP, Mac, email, name, username)

I am creating block lists to block user actions based on IP address, MAC address, Email address, Name (first/last name), Trademark names and Usernames. So should each of these be a separate lookup table or can there be one blocked_list table with all these in? Each is individual independent of the other.
The list will be used in few places ->
User signup - block account signup based on IP, MAC, email & any disallowed First/last name
Username creation - block username creation based on restricted usernames
Profile details - block profile email being added based on disallowed emails
Public pages - block people from naming pages based on a restricted list of trademarked names.
Also, is it better to keep this in the DB or a text file? Except trademark names everything else will be in English. For trademarks I may use region specific blocking so need multi-lang support.
I'd make each their own table.
how would combining them make your queries run any faster? it wouldn't.
It isn't like you won't know what you have, if you have a MAC address check in the block MAC address table for it, it would be your primary key which would be defined to the exact proper length and type for a MAC address.
What about having 1 table with all the values in and have a column - block_type. You will need a lookup table for block_type where 1=IP. 2 =MAC,... This was you can manage this with only 2 tables. But I'll let someone more professional answer this as I am new myself to databases.
You can put all the entries in a single table. Check out the Entity-Attribute-Value approach or use a schemaless NoSQL datastore.
http://en.wikipedia.org/wiki/Entity-attribute-value_model
If you're processing the 'blocking' in the middle tier, you can just dump the lists as serialized objects (e.g. JSON) into the table.

Resources