Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Questions on implementation? #33

Open
RobStallion opened this issue Jan 28, 2019 · 4 comments
Open

Questions on implementation? #33

RobStallion opened this issue Jan 28, 2019 · 4 comments

Comments

@RobStallion
Copy link
Member

Creating an issue as a place to ask questions on implementation.

Why do we have the function check_for_unique_index()? I'm guessing it is because alog cannot be used on tables that have unique index applied but the why is not obvious to me.

@RobStallion RobStallion added help wanted Extra attention is needed question Further information is requested labels Jan 28, 2019
@Danwhy
Copy link
Member

Danwhy commented Jan 29, 2019

If a table has a unique index on a particular column, eg: email, it would mean that you cannot have two rows in the database with the same email. So when a row is updated, the row is completely replaced, meaning there will still only be one row with a particular email.

However with Alog, if we update a row it will create a new row, so there will now be two rows with the same email. If the table has a unique index, this won't be allowed and the update entry will just be rejected.

So to avoid these errors in updating, we need to make sure a table does not have a unique index applied when Alog is used.

@RobStallion RobStallion removed question Further information is requested help wanted Extra attention is needed labels Jan 29, 2019
@RobStallion
Copy link
Member Author

RobStallion commented Feb 13, 2019

@Danwhy why is the query in the all/0 function split into sub and query?

        sub =
          from(m in __MODULE__,
            distinct: m.entry_id,
            order_by: [desc: :updated_at],
            select: m
          )

        query = from(m in subquery(sub), where: not m.deleted, select: m)

Would we be able to do this in one query like so?

from(m in __MODULE__, distinct: m.entry_id, order_by: [desc: :updated_at], where: not m.deleted)

(I'm guessing not but I can't see any reason why. If someone can explain if I am missing something that would be 👍 )

@RobStallion RobStallion added the question Further information is requested label Feb 13, 2019
@RobStallion
Copy link
Member Author

Don't know why I didn't think of this last night 😑

I'll just check it myself by updating the query and running the tests locally.

@RobStallion RobStallion removed the question Further information is requested label Feb 14, 2019
@Danwhy
Copy link
Member

Danwhy commented Feb 14, 2019

@RobStallion If we do it all in one, the order_by isn't applied until after the results are selected, so there's no guarantee we'll get the latest one in the distinct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants