Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
24 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Jelixir

Jelixir

command input output
mix jelixir json book.json book.json - Created schema file: jelixir/book.ex
- Created migration file: jelixir/create_book.ex
mix jelixir phx book.json book.json Created Phoenix tasks file: jelixir/book.jelixir
mix jelixir schema book.ex book.ex Created Phoenix tasks file: jelixir/book.jelixir
  1. Convert JSON content to elixir files:
  • Schema file
  • Migration file
  1. Conver JSON content to phoenix script content, included phx.gen.context,phx.gen.html and phx.gen.json script:

  2. Conver Schema content file to phoenix script content, included phx.gen.context,phx.gen.html and phx.gen.json script

Input

  • JSON content: book.json for mix jelixir json book.json, mix jelixir phx book.json
{
  "code": "PPP12",
  "edition": "2st",
  "price": 23000,
  "publisher": "NXBGD",
  "title": "Toán học cao cấp",
  "createdAt": "2020/11/29",
  "updatedAt": "2020/11/29"
}
  • Schema file: book.ex for mix jelixir schema book.ex
defmodule Book do
  use Ecto.Schema

  schema "book" do
    field(:code, :string)
    field(:createdAt, :string)
    field(:edition, :string)
    field(:price, :integer)
    field(:publisher, :string)
    field(:title, :string)
    field(:updatedAt, :string) 
  end
end

Ouput

  • Created Phoenix tasks file: jelixir/book.jelixir
# Generates a context with functions around an Ecto schema.
# https://hexdocs.pm/phoenix/Mix.Tasks.Phx.Gen.Context.html#content

mix phx.gen.context ModuleBook Book book \
    code:string \
    createdAt:string \
    edition:string \
    price:integer \
    publisher:string \
    title:string \
    updatedAt:string

# Generates controller, views, and context for an HTML resource. 
# https://hexdocs.pm/phoenix/Mix.Tasks.Phx.Gen.Html.html#content

mix phx.gen.html ModuleBook Book book \
    code:string \
    createdAt:string \
    edition:string \
    price:integer \
    publisher:string \
    title:string \
    updatedAt:string

# Generates controller, views, and context for a JSON resource.
# https://hexdocs.pm/phoenix/Mix.Tasks.Phx.Gen.Json.html#content

mix phx.gen.json ModuleBook Book book \
    code:string \
    createdAt:string \
    edition:string \
    price:integer \
    publisher:string \
    title:string \
    updatedAt:string
  • Created schema file: jelixir/book.ex
defmodule Book do
  use Ecto.Schema

  schema "book" do
    field(:code, :string)
    field(:createdAt, :string)
    field(:edition, :string)
    field(:price, :integer)
    field(:publisher, :string)
    field(:title, :string)
    field(:updatedAt, :string) 
  end
end
  • Created migration file: jelixir/create_book.ex
defmodule REPO_NAME.Migrations.CreateBookTable do
  use Ecto.Migration

  def change do
    create table("book") do
      add(:code, :string)
      add(:createdAt, :string)
      add(:edition, :string)
      add(:price, :integer)
      add(:publisher, :string)
      add(:title, :string)
      add(:updatedAt, :string)
      timestamps()
    end
  end
end

About

convert json content to elixir schema file and elixir migration file.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.