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

Insert #50

Merged
merged 19 commits into from
Mar 7, 2019
Merged

Insert #50

merged 19 commits into from
Mar 7, 2019

Conversation

RobStallion
Copy link
Member

@RobStallion RobStallion commented Feb 28, 2019

#45

"alog-ifies" insert functionality, adding a CID made from the params and a unique entry_id from a substring of the CID.

Adds tests for insert function

This step, as it is currently, allows for duplicate data to be inserted. Comments have been added to code for my thoughts on this matter.

@RobStallion
Copy link
Member Author

@Danwhy I do not think that this PR is complete (at all) but I think that it might be in a place that it can be merged into the adapter branch.

Please let me know if you have any thoughts on this.

Copy link
Member

@nelsonic nelsonic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RobStallion looking good so far. 👀 👍

@Danwhy
Copy link
Member

Danwhy commented Feb 28, 2019

I think if we add some tests, we may get a better idea of how we want it to actually work/what makes sense with regards to duplicate data etc.

You'll need to delete or comment out all the old tests that have use Alog in them to run any tests you write. Take a look at the update test on my update branch if you need any help getting started.

@RobStallion
Copy link
Member Author

Testing the insert functions has 'brought to light' some things that we could (and maybe should) change in the future. Please see this comment for more info on this.

@RobStallion RobStallion requested review from Danwhy and SimonLab and removed request for SimonLab and Danwhy March 4, 2019 12:36
@RobStallion RobStallion assigned nelsonic and unassigned SimonLab and Danwhy Mar 4, 2019
Copy link
Member

@Danwhy Danwhy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. Definitely a good idea to get this in to the adapter branch 👍

@RobStallion RobStallion changed the title Insert [WIP] Insert Mar 4, 2019
defp create_entry_id(source, adapter_meta, cid, n) do
entry_id = String.slice(cid, 0..n)
entry_id_query = "SELECT * FROM #{source} where entry_id='#{entry_id}'"
{:ok, results} = Ecto.Adapters.SQL.query(adapter_meta, entry_id_query, [])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might be able to enhance this existing cid lookup later on. Maybe we could use a cache system to store all the current cid (with ETS)? If we can manage to not send another query to Postgres that would be ideal but it's working for now 👍

lib/alog.ex Outdated
defp insert_logic(adapter_meta, source, prefix, params, on_conflict, returning, opts) do
{kind, conflict_params, _} = on_conflict
{fields, values} = :lists.unzip(params)
sql = @conn.insert(prefix, source, fields, [fields], on_conflict, returning)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how/where the @conn module attribute is defined, I can't see it being done in the Alog module.
I think a @conn is defined before the adapter is being called but I think module attributes are scoped to the module and can't be use in other modules (didn't find any explanation on the scope of the module on the Elixir doc https://elixir-lang.org/getting-started/module-attributes.html)

@RobStallion do you know where it is defined?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SimonLab That's a really good spot. I meant to change that. It is defined here in the Ecto.Adapter.SQL module. As it is a defined in a macro it looks like the module using it inherits the module attributes as well.

I agree that it is SUPER unclear though so I'll update it now 👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok makes sense, so to recap because Ecto.Adapters.SQL module is used in Alog, all the module attributes in the macro are accessible on Alog.

defmodule Alog do
  use Ecto.Adapters.SQL,

and

  defmacro __using__(opts) do
    quote do
      @behaviour Ecto.Adapter
      @behaviour Ecto.Adapter.Migration
      @behaviour Ecto.Adapter.Queryable
      @behaviour Ecto.Adapter.Schema
      @behaviour Ecto.Adapter.Transaction

      opts = unquote(opts)
      @conn __MODULE__.Connection
...

Copy link
Member

@SimonLab SimonLab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RobStallion looks good, just a question about the module attribute @conn

Copy link
Member

@SimonLab SimonLab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After creating the table and running the migrations the tests are green 🎉
image

Thanks @RobStallion 👍

@SimonLab SimonLab mentioned this pull request Mar 6, 2019
3 tasks
end
end
end
# use Alog.TestApp.DataCase
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when commenting out an entire file, consider adding a line at the top explaining why.
otherwise the next person reading it will scratch their heads and have to do forensics to understand it. 🤔

Copy link
Member

@nelsonic nelsonic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RobStallion insert is looking good. ✅
Please consider leaving a comment (preferably linking to an issue/discussion) explaining why several tests are commented out. 💬
Happy to merge into adapter branch to continue work. 👍

@nelsonic nelsonic merged commit a057334 into adapter Mar 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants