Skip to content

Commit

Permalink
Cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
rtshkmr committed Jan 28, 2024
1 parent d822440 commit 7c54867
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 405 deletions.
207 changes: 0 additions & 207 deletions docs/gita_cloning.livemd

This file was deleted.

39 changes: 5 additions & 34 deletions docs/ritesh_roughwork.livemd → docs/initial_db_helpers.livemd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Ritesh's Rough Work on Vyasa
# 2024 - An Ecto Odessy [Initial DB Helpers]

## Root Section -- Common Utils

Expand Down Expand Up @@ -149,15 +149,6 @@ defmodule G do
end
```

```elixir
# improving on the get-* functions

sid = Ecto.UUID.generate()

verses = G.get_verses(sid)
chapters = G.get_chapters(verses, sid)
```

#### DB Convenience Actions

* purging of db
Expand Down Expand Up @@ -212,36 +203,24 @@ DBHelper.purge_db()
DBHelper.seed_db()
```

```elixir
R.recompile()sr
alias Vyasa.Written

Written.get_source_by_title("Gita")
```

<!-- livebook:{"branch_parent_index":0} -->

## Exploration

```elixir
DBHelper.purge_db()
DBHelper.seed_db()
# DBHelper.purge_db()
# DBHelper.seed_db()

alias Vyasa.Written
sources = Written.list_sources() |> Repo.preload([:chapters, :verses])
s = hd(sources)
v = hd(s.verses)
c = hd(s.chapters)
Map.keys(c)
c

# Written.get_source!(hd(sources).id)
```

```elixir
DBHelper.seed_db()
```

```elixir
R.recompile()

Expand All @@ -258,15 +237,11 @@ Written.get_chapter!(2, id)

## 2) Cloning Gita by Creating a Schema for it

### Actually creating entries:
### Check Queries found in the Written context module

<!-- livebook:{"break_markdown":true} -->

#### Improving the ingestion to include missed attributes

<!-- livebook:{"break_markdown":true} -->

### Check Queries
###

```elixir
R.recompile()
Expand All @@ -290,8 +265,4 @@ chapter.verses
|> Repo.preload([:source, :chapter])
```

```elixir

```

#### Session Creation
46 changes: 0 additions & 46 deletions lib/vyasa/written.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,12 @@ defmodule Vyasa.Written do
[%Source{}, ...]
"""

def list_sources do
Repo.all(Source)
|> Repo.preload([:chapters, :verses])
end



@doc """
Gets a single text.
Expand Down Expand Up @@ -79,69 +77,27 @@ defmodule Vyasa.Written do

end

# def get_chapter(no, source_id) do
# Repo.get_by!(Chapter, no: no, source_id: source_id)
# |> Repo.preload([:verses])
# end

# def get_chapter!(no, source_id) do
# Repo.get_by!(Chapter, no: no, source_id: source_id)
# |> Repo.preload([:verses])
# end

def get_chapter(no, source_title) do
src = list_sources()
|>Enum.find(fn src -> src.title == source_title end)
Repo.get_by(Chapter, no: no, source_id: src.id)
|> Repo.preload([:verses])

end

def get_verses_in_chapter(no, source_id) do
chapter = Repo.get_by(Chapter, no: no, source_id: source_id)
|> Repo.preload([:verses])

chapter.verses

end

def get_verse_via_url_params(verse_no, chap_no, source_title) do
# chapter = Repo.get_by(Chapter, no: chap_no, source_id: source_id)
# |> Repo.preload([:verses])

# chapter.verses
# |> Enum.find(fn verse -> verse.no === verse_no end)

# IO.puts("get_verse_via_url_params")
# IO.inspect(verse_no)

# # get_chapter(chap_no, source_id)
# get_verses_in_chapter(chap_no, source_id)
# |> Enum.find(fn verse -> verse.no == verse_no end)

# chapter = Repo.get_by(Chapter, no: chap_no, source_id: source_id)
# |> Repo.preload([:verses, :source])

chapter = get_chapter(chap_no, source_title)
|> Repo.preload([:verses, :source])

chapter.verses
|> Enum.find(fn verse -> verse.no == verse_no end)
|> Repo.preload([:chapter, :source])










# get_verses_in_chapter(chap_no, source_id)
# |> Enum.find(fn verse -> verse.no === verse_no
# end)

end

@doc """
Expand Down Expand Up @@ -200,10 +156,8 @@ defmodule Vyasa.Written do
Returns an `%Ecto.Changeset{}` for tracking text changes.
## Examples
iex> change_text(text)
%Ecto.Changeset{data: %Text{}}
"""
def change_text(%Text{} = text, attrs \\ %{}) do
Text.changeset(text, attrs)
Expand Down
1 change: 0 additions & 1 deletion lib/vyasa/written/verse.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ defmodule Vyasa.Written.Verse do
schema "verses" do
field :no, :integer
field :body, :string
# QQ: compiler was looking for this but not sure what made it look for this field since the migration file doesn't use this name

belongs_to :source, Source, type: Ecto.UUID
belongs_to :chapter, Chapter, type: :integer, references: :no, foreign_key: :chapter_no
Expand Down
Loading

0 comments on commit 7c54867

Please sign in to comment.