Git Product home page Git Product logo

ecto_ksuid's Introduction

ecto_ksuid

Build Status Hex.pm Version Hexdocs Downloads License MIT

EctoKsuid allows seamless usage of ksuids with :ecto in your application. To get a better idea of what ksuids are, and how they came to be I highly recommend reading A breif History of the UUID

[Ksuid] borrows core ideas from the ubiquitous UUID standard, adding time-based ordering and more friendly representation formats.

Additionally, EctoKsuid allows easy addition of a :prefix to the ksuid that are available at runtime. This generates developer friendly ids much like stripe's object prefixed ids in your elixir application.

Example Ksuids using the "user_" prefix

  • "user_2EgT2R97RRNXWXdA3Ov6znVLDCd"
  • "user_2EgT5YAJ1EMj86IdI8In8Cmfsnj"
  • "user_2EgT6WuSzOmcF9bZaRdS3X6lEaL"
  • "user_2EgT7SEl7LaIGIHIQ1gIjB9eVwT"
  • "user_2EgT8B20KvdsIQznKX6Tuh2RGDe"

Documentation

Documentation can be found online on HexDocs.

Installation

  1. Add :ecto_ksuid to your list of dependencies in mix.exs

    def deps do
      [
        # ...
        {:ecto_ksuid, "~> 0.3.0"}
      ]
    end
  2. Install using mix.

    mix deps.get

Basic Usage

EctoKsuid is just a custom Ecto.ParameterizedType and can be used in your application just like any other Ecto type.

  1. Add columns to your database

    defmodule MyApp.Repo.Migrations.AddPublicIdToUsers do
      use Ecto.Migration
    
      def change do
        alter table(:users) do
          add :public_id, EctoKsuid.column()
        end
      end
    end
  2. Add fields to your schema

    defmodule MyApp.User do
      use Ecto.Schema
    
      schema "users" do
        # ...
        field :public_id, EctoKsuid
      end
    end

Guides

For more details on how to use this library, check out the guides:

ecto_ksuid's People

Contributors

benstepp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.