1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-03 23:28:02 +00:00

Add Creating Indexes With Ecto as an elixir til

This commit is contained in:
jbranchaud
2016-12-31 15:52:52 -06:00
parent c5942e2a68
commit 7935729c6e
2 changed files with 21 additions and 1 deletions

View File

@@ -7,7 +7,7 @@ variety of languages and technologies. These are things that don't really
warrant a full blog post. These are mostly things I learn by pairing with
smart people at [Hashrocket](http://hashrocket.com/).
_494 TILs and counting..._
_495 TILs and counting..._
---
@@ -88,6 +88,7 @@ _494 TILs and counting..._
- [Binary Representation Of A String](elixir/binary-representation-of-a-string.md)
- [Check For A Substring Match](elixir/check-for-a-substring-match.md)
- [Create A Date With The Date Sigil](elixir/create-a-date-with-the-date-sigil.md)
- [Creating Indexes With Ecto](elixir/creating-indexes-with-ecto.md)
- [Determine The Latest Release Of A Hex Package](elixir/determine-the-latest-release-of-a-hex-package.md)
- [Do You Have The Time?](elixir/do-you-have-the-time.md)
- [Do You Have The Time? - Part 2](elixir/do-you-have-the-time-part-2.md)

View File

@@ -0,0 +1,19 @@
# Creating Indexes With Ecto
Using indexes in the right places within relational databases is a great way
to speed up queries and ensure data integrity.
To add a basic index in an Ecto migration, use `Ecto.Migration.index\2`:
```elixir
create index(:users, [:email])
```
Creating a composite index doesn't require jumping through any hoops; just
put the relevant column names in the list:
```elixir
create index(:posts, [:user_id, :title])
```
See `h Ecto.Migration.index` for more details.