mirror of
https://github.com/jbranchaud/til
synced 2026-01-04 23:58:01 +00:00
Add Creating Indexes With Ecto as an elixir til
This commit is contained in:
@@ -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
|
warrant a full blog post. These are mostly things I learn by pairing with
|
||||||
smart people at [Hashrocket](http://hashrocket.com/).
|
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)
|
- [Binary Representation Of A String](elixir/binary-representation-of-a-string.md)
|
||||||
- [Check For A Substring Match](elixir/check-for-a-substring-match.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)
|
- [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)
|
- [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?](elixir/do-you-have-the-time.md)
|
||||||
- [Do You Have The Time? - Part 2](elixir/do-you-have-the-time-part-2.md)
|
- [Do You Have The Time? - Part 2](elixir/do-you-have-the-time-part-2.md)
|
||||||
|
|||||||
19
elixir/creating-indexes-with-ecto.md
Normal file
19
elixir/creating-indexes-with-ecto.md
Normal 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.
|
||||||
Reference in New Issue
Block a user