1<!DOCTYPE html> 2<html data-n-head-ssr data-n-head=""> 3 <head> 4 <meta data-n-head="true" charset="utf-8"/><meta data-n-head="true" name="viewport" content="width=device-width, initial-scale=1"/><meta data-n-head="true" data-hid="description" name="description" content="this is blog of tomu"/><title data-n-head="true">blog of technology, business and thought.</title><link data-n-head="true" rel="icon" type="image/x-icon" href="/favicon.ico"/><link data-n-head="true" rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/minireset.css/0.0.2/minireset.min.css"/><link rel="preload" href="/_nuxt/manifest.87096ebca27225c201a7.js" as="script"><link rel="preload" href="/_nuxt/vendor.0569240daded7799509b.js" as="script"><link rel="preload" href="/_nuxt/app.f8753dd5602b24157b28.js" as="script"><link rel="prefetch" href="/_nuxt/pages/index.474797902786d1d67978.js"><link rel="prefetch" href="/_nuxt/pages/tags/_tag.9d44e4503989d92823c8.js"><link rel="prefetch" href="/_nuxt/pages/blog/index.eec9a79f18493e0619cb.js"><link rel="prefetch" href="/_nuxt/layouts/default.123dbbcd236b5c8a655e.js"><link rel="prefetch" href="/_nuxt/pages/blog/_slug.63c7dbd88513c7144350.js"><style data-vue-ssr-id="7285e09c:0">.nuxt-progress{position:fixed;top:0;left:0;right:0;height:2px;width:0;transition:width .2s,opacity .4s;opacity:1;background-color:#efc14e;z-index:999999}</style><style data-vue-ssr-id="2bb99bec:0">@font-face{font-family:Avenir;font-weight:400;font-style:normal;src:url(/_nuxt/fonts/avenir-400.457e94a.woff2) format("woff2");font-display:swap}body{background:#e1e7ea;max-width:1180px;margin:0 auto;font-family:Avenir,Tahoma,Arial,Helvetica,sans-serif;font-size:16px;line-height:1.65;color:#373f49}.wrapper{padding:2em 0;max-width:80%;margin:0 auto}.header{background:#f7f9fa}.page-bar{max-width:100%;padding:2em 10%}.blog.header h2,.tag-page.header h2{text-align:center;padding:2.5em 0;color:#a0a0a0}img{display:block;width:100%}h1,h2,h3{font-size:2em}.body-container{background:#fff}.items-list{overflow:hidden}.item{padding:1em 3em 1em 0}@media (min-width:600px){.item{float:left;width:50%}}@media (min-width:900px){.item{width:33.333%}}.tiny{text-transform:uppercase;font-size:10px;letter-spacing:1px;color:#a0a0a0}[class*=-bar]{border-bottom:1px solid #ebebeb}pre{padding:1em;margin-left:20px;color:#666;background-color:#f0f0f0;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word}code{font-family:monospace;font-weight:400;line-height:150%;text-align:left;margin-bottom:10px}</style><style data-vue-ssr-id="395946eb:0">.person-name:link,.person-name:visited{width:50%;display:inline-block;font-size:2em;text-decoration:none;color:#373f49}.top-nav{width:50%;text-align:right}.menu,.menu li,.top-nav{display:inline-block}.menu li{margin-left:1em}.menu a:link,.menu a:visited{color:#373f49;text-decoration:none}</style><style data-vue-ssr-id="28c0af02:0">.thumbnail{margin-bottom:1em}.title{text-decoration:none;font-size:22px;color:#373f49}.tags{padding:1em 0;margin-bottom:2em}.tag:link,.tag:visited{color:#a0a0a0;text-decoration:none;display:inline-block;padding:.33333rem .5rem;line-height:1;border-radius:2px;border:1px solid #a0a0a0;margin-right:.5em}.tag:active,.tag:focus,.tag:hover{color:#606060;border-color:#606060}</style> 5 </head> 6 <body data-n-head=""> 7 <div data-server-rendered="true" id="__nuxt"><div class="nuxt-progress" style="width:0%;height:2px;background-color:#2199e8;opacity:0;"></div><div id="__layout"><div class="container"><main role="main"><div><header class="tag-page header"><div class="foreground"><div class="page-bar wrapper"><a href="/" class="person-name">Tomu Blog</a><nav role="navigation" class="top-nav"><ul class="menu"><li><a href="/blog">Blog</a></li><!----><!----><li><a href="/" class="nuxt-link-active">Index</a></li></ul></nav></div><div class="page-info wrapper"><h2>#elixir</h2></div></div></header><section class="body-container"><div class="items-bar wrapper"><h2>All articles tagged #elixir (1)</h2></div><ul class="items-list wrapper"><li class="item"><article><img src="//images.ctfassets.net/r1ueailrte7y/271It4mjkxx9NEr9JDfRXK/e6cbe1f8392fcf4abaec3d590c43fc72/____________________________2019-12-20_21.05.59.png?fit=scale&w=350&h=196" srcset="//images.ctfassets.net/r1ueailrte7y/271It4mjkxx9NEr9JDfRXK/e6cbe1f8392fcf4abaec3d590c43fc72/____________________________2019-12-20_21.05.59.png?w=350&h=196&fit=fill 350w, //images.ctfassets.net/r1ueailrte7y/271It4mjkxx9NEr9JDfRXK/e6cbe1f8392fcf4abaec3d590c43fc72/____________________________2019-12-20_21.05.59.png?w=1000&h=562&fit=fill 1000w, //images.ctfassets.net/r1ueailrte7y/271It4mjkxx9NEr9JDfRXK/e6cbe1f8392fcf4abaec3d590c43fc72/____________________________2019-12-20_21.05.59.png?w=2000&h=1125&fit=fill 2000w" sizes="(min-width: 1024px) 400px, 100vw" class="thumbnail"><time class="tiny date">Tue Dec 24 2019</time><h4><a href="/blog/ecto-task" class="title">ectoåºæ¬taskã¾ã¨ã</a></h4><p>ãªããªã解説ãã¦ããè¨äºã®ãªãelixirã®ORãããã¼ã§ããectoSQLã®taskãåå¿é²ã¨ãã¦ã¾ã¨ãã¾ããã</p><div class="tags"><a href="/tags/elixir" class="tag nuxt-link-exact-active nuxt-link-active">elixir</a><a href="/tags/phoenix" class="tag">phoenix</a><a href="/tags/SQL" class="tag">SQL</a></div></article></li></ul></section></div></main></div></div></div>
7<script type="text/javascript">window.__NUXT__={"layout":"default","data":[{"posts":[{"metadata":{"tags":[],"concepts":[]},"sys":{"space":{"sys":{"type":"Link","linkType":"Space","id":"r1ueailrte7y"}},"id":"3rHwG37PlNT0EqE5yJ4kc0","type":"Entry","createdAt":"2019-12-20T12:06:58.124Z","updatedAt":"2019-12-24T12:51:59.626Z","environment":{"sys":{"id":"master","type":"Link","linkType":"Environment"}},"publishedVersion":1710,"revision":6,"contentType":{"sys":{"type":"Link","linkType":"ContentType","id":"blogPost"}},"locale":"en-US"},"fields":{"title":"ectoåºæ¬taskã¾ã¨ã","slug":"ecto-task","heroImage":{"metadata":{"tags":[],"concepts":[]},"sys":{"space":{"sys":{"type":"Link","linkType":"Space","id":"r1ueailrte7y"}},"id":"271It4mjkxx9NEr9JDfRXK","type":"Asset","createdAt":"2019-12-20T12:06:45.894Z","updatedAt":"2019-12-20T12:06:45.894Z","environment":{"sys":{"id":"master","type":"Link","linkType":"Environment"}},"publishedVersion":7,"revision":1,"locale":"en-US"},"fields":{"title":"ectoSQL","file":{"url":"\u002F\u002Fimages.ctfassets.net\u002Fr1ueailrte7y\u002F271It4mjkxx9NEr9JDfRXK\u002Fe6cbe1f8392fcf4abaec3d590c43fc72\u002F____________________________2019-12-20_21.05.59.png","details":{"size":506205,"image":{"width":2594,"height":1604}},"fileName":"ã¹ã¯ãªã¼ã³ã·ã§ãã 2019-12-20 21.05.59.png","contentType":"image\u002Fpng"}}},"description":"ãªããªã解説ãã¦ããè¨äºã®ãªãelixirã®ORãããã¼ã§ããectoSQLã®taskãåå¿é²ã¨ãã¦ã¾ã¨ãã¾ããã","body":"## ã¯ããã«\nãã®è¨äºã¯estie Advent Calendar 2019 24æ¥ç®ã®è¨äºã«ãªãã¾ãã\nä»ã®è¨äºã«ã¤ãã¦ã¯[ãã¡ã](https:\u002F\u002Fqiita.com\u002Fadvent-calendar\u002F2019\u002Festie \"estie advent calender\")ããã覧ä¸ããã\n\n### ectoã§è²ã
ãã£ã¦ã¿ã\nã§ã¯æ©éectoã§sqlãæä½ãã¦ã¿ã¾ãããã\nã¾ãã¯ä»¥ä¸ã®ã³ãã³ãã§æ°ããphoenixããã¸ã§ã¯ãã使ããã\n```\n$ mix phx.new test_app\n```\n\ndockerã§ãã¹ãç¨ã®postgresSQLãç«ã¦ãããã«ä»¥ä¸ã®docker-compose.ymlãæ¸ãã¾ã\n```\nversion: \"3\"\n\nservices:\n postgresql:\n image: postgres:10.5\n container_name: postgresql\n ports:\n - 5432:5432\n volumes:\n - .\u002Fpostgres\u002Finit:\u002Fdocker-entrypoint-initdb.d\n environment:\n POSTGRES_USER: root\n POSTGRES_PASSWORD: root\n POSTGRES_INITDB_ARGS: \"--encoding=UTF-8\"\n hostname: postgres\n restart: always\n user: root\n ```\n \n ããã¦postgresSQLãµã¼ãã¼ãç«ã¦ã\n ```\n $ docker-compose up\n ```\n \n postgresãã¼ã¿ãã¼ã¹ã¯ãã§ã«ã§ãã¦ããã¨æãã®ã§è©¦ãã«DBã«ç¹ãã§ã¿ã¾ã\n ```\n psql -h localhost -p 5432 -U root -d postgres\n ```\n ãã¹ã¯ã¼ããèããããdocker-compose.ymlã«æ¸ããéãrootã¨æã£ã¦ä¸ããã\n \n ã¾ãectoãpostgresã«æ¥ç¶ã§ããããã«ä»¥ä¸ã®ããã«config\u002Fdev.exsãæ¸ãæãã¾ãã\n ```\n # Configure your database\nconfig :test_app, TestApp.Repo,\n username: \"root\",\n password: \"root\",\n database: \"test_app_dev\",\n hostname: \"localhost\",\n show_sensitive_data_on_connection_error: true,\n pool_size: 10\n```\nã¯ããã§ã¯ãã¼ãã«ã使ãã¾ãã\n \n ```\n $ mix ecto.create\n ```\nããã§databaseãã§ãã¾ããã\nDBã«å
¥ã£ã¦ç¢ºèªãã¾ãã\n```\n$ psql -h localhost -p 5432 -U root -d test_app_dev\n\ntest_app_dev=#\\l\n List of databases\n Name | Owner | Encoding | Collate | Ctype | Access privileges \n--------------+-------+----------+------------+------------+-------------------\n postgres | root | UTF8 | en_US.utf8 | en_US.utf8 | \n root | root | UTF8 | en_US.utf8 | en_US.utf8 | \n template0 | root | UTF8 | en_US.utf8 | en_US.utf8 | =c\u002Froot +\n | | | | | root=CTc\u002Froot\n template1 | root | UTF8 | en_US.utf8 | en_US.utf8 | =c\u002Froot +\n | | | | | root=CTc\u002Froot\n test_app_dev | root | UTF8 | en_US.utf8 | en_US.utf8 | \n(5 rows)\n```\nã
7§ãã¦ã¾ããã\n\n次ã«ãã¼ãã«ãä½ã£ã¦ããã¾ãã\npheonixã«mixã¿ã¹ã¯ã§railsã®rails g Modelã®ããã«ã¢ãã«ãã¡ã¤ã«ãã¨ä½ãphx.gen.schemaãscaffoldã®ããã«viewãã¡ã¤ã«ãã¨ä½ã£ã¦ãããphx.gen.htmlãªã©ãããã¾ããããã§ã¯ectoã§migrationãã¡ã¤ã«ã使ãã¾ãã\n```\n$ mix ecto.gen.migration add_posts_table\n```\npriv\u002Frepo\u002Fmigrations以ä¸ã«migrationãã¡ã¤ã«ãã§ããã¨æãã¾ãã\nããã«postãã¼ãã«ã使ããã³ã¼ããæ¸ãã¦ããã¾ãã\n```\ndefmodule TestApp.Repo.Migrations.AddPostsTable do\n use Ecto.Migration\n\n def change do\n create table(:posts) do\n add :title, :string, default: \"Untitled\"\n add :body, :text\n\n timestamps()\n end\n end\nend\n```\n\nmigrationãè¡ãããã¼ãã«ã使ãã¾ãã\n```\n$ mix ecto.migrate\n```\n\nãã¼ãã«ãã§ãããã¨ã確èªãã¾ãã\n```\ntest_app_dev=#\\dt;\n\n List of relations\n Schema | Name | Type | Owner \n--------+-------------------+-------+-------\n public | posts | table | root\n public | schema_migrations | table | root\n(2 rows)\n\n\ntest_app_dev-# \\d posts;\n\nTable \"public.posts\"\n Column | Type | Collation | Nullable | Default \n-------------+--------------------------------+-----------+----------+-----------------------------------\n id | bigint | | not null | nextval('posts_id_seq'::regclass)\n title | character varying(255) | | | 'Untitled'::character varying\n body | text | | | \n inserted_at | timestamp(0) without time zone | | not null | \n updated_at | timestamp(0) without time zone | | not null | \nIndexes:\n \"posts_pkey\" PRIMARY KEY, btree (id)\n\n```\nã
7§ãã¦ãã¾ãããrailsåæ§ã®rollbackå¦çãã§ãã¾ãã\n```\n$ mix ecto.rollback\n```\nåã³ãã¼ãã«ä¸è¦§ã確èªããã¨ã\n```\n List of relations\n Schema | Name | Type | Owner \n--------+-------------------+-------+-------\n public | schema_migrations | table | root\n(1 row)\n```\nãã¼ãã«ãdropããã¦ãã¾ããã\n次ã«postsãã¼ãã«ã«ã«ã©ã ã追å ãã¾ãããã\n```\n$ mix ecto.gen.migration add_point_to_posts\n```\nçæããããã¡ã¤ã«ã以ä¸ã®ããã«ç·¨éãã¾ãã\n```\ndefmodule TestApp.Repo.Migrations.AddPointToPosts do\n use Ecto.Migration\n\n def change do\n alter table(\"posts\") do\n add :point, :bigint\n add :summary, :text \n add :object, :map \n end\n end\nend\n```\nmigrateãã¦ä¸ãããpostsãã¼ãã«ã«ã«ã©ã ã追å ãããã¨æãã¾ãã(å ã¿ã«documentã«æç¤ºããã¦ãªãã®ã§ãã:bigintã§bigintåã«ã§ãã¾ã)\nãã®ã»ãã«ãåæ§ã®è¨æ³ã§ã«ã©ã ã®åé¤ãååã®å¤æ´ãè¡ãã¾ãã\n\n## ã¾ã¨ã\n以ä¸ç°¡åã«ã§ããectoã®ä½¿ç¨æ¹æ³ãã¾ã¨ãã¦ã¿ã¾ãããrailsã¨ä¼¼ãè¨æ³ã§ç°¡åã«ãã¼ãã«ã®ä½æã夿´ãè¡ããã¨ãã§ãã¾ãã詳ããå
容ã«ã¤ãã¦ã¯[ãã¡ã](https:\u002F\u002Fhexdocs.pm\u002Fecto_sql \"ecto\")ãåç
§ãã¦ä¸ããã\n\næ ªå¼ä¼ç¤¾estieã§ã¯elixir\u002Fphoenixãapiãµã¼ãã¼ã¨ãã¦ä½¿ç¨ãã¦ããã¾ããæ°ããªæè¡ã¸ã®å¥½å¥å¿ã®å¼·ãã¨ã³ã¸ãã¢ã®æ¹ã
ãã²ä¸ç·ã«ãµã¼ãã¹ãä½ã£ã¦ããã¾ãããã\n\n### è£è¶³ã\n以ä¸ã®ã³ãã³ãã§databaseã®æ§é ãsqlãã¡ã¤ã«ã«dumpã§ãã¾ã\n```\n$ mix ecto.dump\n```\nããã¦databaseãèªã¿è¾¼ã¿ã¾ãã\n```\n$ mix ecto.load\n```","publishDate":"2019-12-24T12:00+09:00","tags":["elixir","phoenix","SQL"]}}],"tag":"elixir"}],"error":null,"serverRendered":true};</script>
7<script src="/_nuxt/manifest.87096ebca27225c201a7.js" defer></script>
7<script src="/_nuxt/vendor.0569240daded7799509b.js" defer></script>
7<script src="/_nuxt/app.f8753dd5602b24157b28.js" defer></script>
7 8 </body> 9</html>
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.