Hi everyone.
My name is Audun and i’m coming from a team that uses the .NET stack heavily in our development and products.
I got my eyes on Elixir and Phoenix half a year ago and have been playing around with it.
I love it, i love the design and i love the thought behind it.
As my background is OOP for many years i do not find Elixir that dificult to get started with, but i do belive i use quite a longer time to actually understand some of the design patterns and remembering them. But even so, i want to get Elixir into my organization as the primary tool for the different projects we have as long as it fits the need.
I do however have a question. One of my pet project that i have to learn is kinda “twitter” clone. One of the misstakes i did when starting was to find Ecto difficult to understand, and to keep moving forward i started using Postgresql functions since i’m more familiar with that. Now, i have a lot of functions and its quite messy to add new stuff to existing functions and to know whats actually on the server. I want to try the Ecto way. So here is the “thought” out design.
In my twitter clone i have a table called Tweets.
CREATE TABLE public.tweets
id integer NOT NULL
slug character varying(500)
user_id integer
geom geography
CONSTRAINT tweets_user_id_fkey FOREIGN KEY(user_id) REFERENCES public.users(id) MATCH SIMPLE
The user table looks like:
CREATE TABLE public.users
id integer NOT NULL
username character varying(120)
password_hash character varying(250)
A user can be friends with another user:
CREATE TABLE public.friendships
id integer NOT NULL
user_a_id integer
user_b_id integer
accepted boolean
CONSTRAINTS friendships_user_a_id_fkey FOREIGN KEY(user_a_id) REFERENCES public.users(id) MATCH SIMPLE
CONSTRAINTS friendships_user_b_id_fkey FOREIGN KEY(user_b_id) REFERENCES public.users(id) MATCH SIMPLE
A user can also follow a topic
CREATE TABLE public.follows
id integer NOT NULL
user_id integer
topic_id integer
CONSTRAINT follows_topic_id_fkey FOREIGN KEY(topic_id) REFERENCES public.topics(id) MATCH SIMPLE
CONSTRAINT follows_user_id_fkey FOREIGN KEY(user_id) REFERENCES public.users(id) MATCH SIMPLE
So a user can have a friend and a user can follow a topic. When fetching tweets i need to do the following:
a) Find the users friends and fetch tweets.
b) Find the topic the user subscribes to and get tweets
c) Find the tweets the user have added
d) Make sure no duplicates are fetched in the return of A and B.
e) Calculate the distance from where the user are compared to the tweet (see geom on tweet)
I know that this might be overly complicated, but i do thing its as simple as i can get it.
But if i was to use ecto is there a better “design” in the db for this, and if not can this be done in Ecto?
Thanks for reading, and just as i note i have simplified the tables above to only contain the needed fields. Hope this is easy to read and makes sense. Be kind as this is my first post in this forum, and i’m a newbie with Elixir in general.
Thanks