[Phoenix] Mix 命令
mix phx.gen.html 命令生成模板:
# 其中 name 和 age 是 schema 字段名称,后面跟的是类型
# 下面这样的写法,会生成 controller 和 service 层的,但是我们通常不需要生成 service 层面的结构
mix phx.gen.html Account User users [name:string age:integer] # 这样就能生成没有 schema 结构的 HTML 控制:
mix phx.gen.html Account User users --no-context # 但是有时候我们又要把它放在之前生成过的结构下面,方法如下:
# 把 user 放在了之前生成的 Merchant 目录下面,当做是 user 的子目录
mix phx.gen.html Account User users --no-context --web Merchant # 如果不生成 schema 的话,基本 Account 和 students 是随便填的。
# Account 和 students 随便填,会导致 生成的文件中的名称,不对应。这点需要自己改
# Account 是 会查询到服务中有 Account 的模块
# students 是 表名
# 下面是把 Student 放在 Merchant/User/ 下面的文件名
mix phx.gen.html Account Student students --no-context --web Merchant.User
mix ecto.gen.migration migration文件名: 生成 migration 文件
mix phx.gen.schema: 生成 schema,默认生成 migration 文件
# Blog.Post:生成的模块名,如果是这样两层的,会生成 blog 文件夹,然后把 post 放在里面
# blog_posts: 表名
# blog_posts 后面的[可选]: 后面是字段名,和类型
mix phx.gen.schema Blog.Post blog_posts title:string views:integer # 不要生成 migration, 带上参数 --no-migration
mix phx.gen.schema Blog.Post blog_posts --no-migration
mix phx.gen.contenxt 生成 处理数据库查询 API 的模块 :
# Accounts: 文件名,同时也是模块名称,会自动带上根目录的模块名称
# User: schema 的名称
# users: 表名
# users 后面的是字段名[可选]
mix phx.gen.context Accounts User users name:string age:integer # 有时候我们已经生成了 schema, 就不需要再让它生成 schema 了。用戏码的参数
# 默认生成 context 外,还有单元测试的文件 在 test 里面
mix phx.gen.context Accounts User users --no-schema
mix ecto.migrate: migrate 数据库结构
mix ecto.rollback: 回退上一次 migrate
mix phx.routes: # Prints all routes, 打印所有路由
mix clean: # Deletes generated application files, 删除生成的 应用文件
mix phx.server: # Starts applications and their servers, 启动应用和它的服务
mix deps.get: # Gets all out of date dependencies, 获取所有过期依赖项
iex -S mix: # Starts IEx and runs the default task, 启动IEx并运行默认任务
Ps: mix help: 显示所有 mix 命令
mix help 命令: 查看命令的详细帮助,比如 mix help phx.gen.html
下面是命令和它们默认生成的文件部分:
mix phx.digest # Digests and compresses static files
mix phx.digest.clean # Removes old versions of static assets.
mix phx.gen.cert # Generates a self-signed certificate for HTTPS testing
mix phx.gen.channel # Generates a Phoenix channel
mix phx.gen.context # Generates a context with functions around an Ecto schema
mix phx.gen.embedded # Generates an embedded Ecto schema file
mix phx.gen.html # Generates controller, views, and context for an HTML resource
mix phx.gen.json # Generates controller, views, and context for a JSON resource
mix phx.gen.presence # Generates a Presence tracker
mix phx.gen.schema # Generates an Ecto schema and migration file
mix phx.gen.secret # Generates a secret
最新文章
- [修正] Firemonkey 中英文混排折行问题(移动平台)
- 1035-Spell checker(模糊匹配)
- Qt:正则表达式语法:
- 关于oracle数据库的导出导出
- MainData仿Backbone Model式 数据模型记录器
- web安全测试
- [ASE]Sprint1总结 &; Sprint2计划
- highchat中的category编程object问题
- Web Api 控制器
- Activity 与ListActivity的区别
- Python 基础【第三篇】输入和输出
- __block在ARC和非ARC下有什么不同
- DownloadProvider调试
- 使用匿名管道在进程间通信 (System.IO.Pipes使用)(转)
- jsp字段判空
- Django admin 组件 原理分析与扩展使用 之 sites.py (一)
- elasticsearch视频34季
- 每天学习一个命令:find 查找文件
- Dubbo和Spring Cloud微服务架构对比
- react的生命周期需要知道的。