Coder Social home page Coder Social logo

zebbra / ash_uuid Goto Github PK

View Code? Open in Web Editor NEW

This project forked from zoonect-oss/ash_uuid

0.0 0.0 0.0 140 KB

AshUUID: Extension for using UUID v4 and v7, with supports encoding and prefixing

Home Page: https://hexdocs.pm/ash_uuid

License: MIT License

Elixir 100.00%

ash_uuid's Introduction

AshUUID

Hex Hex Docs Build Status License GitHub Stars

Installation

def deps do
  [
    {:ash_uuid, "~> 1.1.1"},
  ]
end

Adoption

Adoption:

  • add {:ash_uuid, "~> 1.1.1"} to your mix.exs project deps;

  • add AshUUID.PostgresExtension to your app Repo's installed_extensions and set AshUUID config migration_default?: true if Postgres-side UUIDs generation is needed;

  • use the extension in your resources use Ash.Resource, data_layer: AshPostgres.DataLayer, extensions: [AshUUID];

  • simply use that for your fields uuid_attribute :id.

Configuration

lib/myapp/repo.ex:

Using the PostgresExtension allows postgres-side uuid-v7 generation.

# App: Postgres migration defaults, not required
`
defmodule Myapp.Repo do
  use AshPostgres.Repo, otp_app: :myapp

  @impl AshPostgres.Repo
  def installed_extensions do
    ["ash-functions", "uuid-ossp", "citext", AshUUID.PostgresExtension]
  end
end

config/config.exs:

# AshUUID: Your otp_app name, required!
config :ash_uuid, :otp_app, :myapp

# Myapp: Customized defaults, not required
config :myapp, :ash_uuid,
  version: 7, # default
  encoded?: true, # default
  prefixed?: true, # default
  migration_default?: true, # default to false
  strict?: true # default to true

# Ash: Type shorthands, not required
config :ash, :custom_types, uuid: AshUUID.UUID

# Ash: Default belongs_to type, not required
config :ash, :default_belongs_to_type, AshUUID.UUID

Usage

defmodule Pineapple do
  use Ash.Resource, data_layer: AshPostgres.DataLayer, extensions: [AshUUID]

  code_interface do
    define_for Area
  end

  postgres do
    table "pineapples"
    repo MyApp.Repo
  end

  attributes do
    uuid_attribute :id, prefix: "pnp"
    create_timestamp :inserted_at
  end

  actions do
    defaults [:create, :read, :update]
  end
end

The full documentation can be found on HexDocs.

Roadmap

Developing

To get set up with the development environment, you will need a Postgres instance and an environment variable DATABASE_URL according to config/config.exs.

You may now generate and apply the test migrations:

mix ash_postgres.generate_migrations
mix ash_postgres.create
mix ash_postgres.migrate
mix test

AshUUID uses ex_check to bundle the test configuration, and simply running mix check should closely follow the configuration used in CI.

Contributing

If you have ideas or come across any bugs, feel free to open a pull request or an issue. You can also find me on the Ash Discord as @moissela.

License

MIT License

Copyright (c) 2023 Alessio Montagnani

See LICENSE.md for details.

ash_uuid's People

Contributors

moissela avatar hwuethrich avatar zachdaniel 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.