美文网首页
Phoenix执行SQL

Phoenix执行SQL

作者: 时见疏星 | 来源:发表于2017-08-16 14:41 被阅读55次

    如何在Phoenix应用中执行 SQL呢?

    首先生成一个migration

    iex> mix ecto.gen.migration my_database_structure_migration
    

    然后在migration中priv/repo/migrations/2017xxxxxxxxxxx_my_database_structure_migration.exs修改:

    defmodule My.Database.Structure.Migration do
      use Ecto.Migration
    
      def up do
        execute File.read!("/path/to/sql_dump.sql")
      end
    
      def down do
        
      end
    end
    

    大功告成!

    https://elixirforum.com/t/how-to-execute-sql-file-script-in-phoenix/7779/2

    相关文章

      网友评论

          本文标题:Phoenix执行SQL

          本文链接:https://www.haomeiwen.com/subject/eiuirxtx.html