Socket
Book a DemoInstallSign in
Socket

ar-sqlite-uuid

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ar-sqlite-uuid

0.0.2
bundlerRubygems
Version published
Maintainers
1
Created
Source

ar-sqlite-uuid

Tests Gem Gem

Override migration methods to support UUID/ULID columns without having to be explicit about it.

Installation

$ gem install ar-sqlite-uuid

Or add the following line to your project's Gemfile:

$ bundle add ar-sqlite-uuid

Also, make sure the extension is loaded. I recommend using sqlpkg. Then you can install the extension you want to use:

$ sqlpkg install asg017/ulid
$ sqlpkg install sqlite/uuid

To load the extension into your sqlite database,

Usage

On your gemfile, you must specify which extension you want to use by loading either ar-sqlite-uuid or ar-sqlite-ulid.

source "https://rubygems.org"

# This will use the `sqlite/uuid` extension.
gem "ar-sqlite-uuid"

# This will use the `asg017/ulid` extension.
gem "ar-sqlite-uuid", require: "ar-sqlite-ulid"

Alternatively, you can also manually define the function that will be used:

# file: config/initialize/active_record.rb

# use ulid
AR::UUID.default_function = "ulid()"

# use ulid with a static prefix
AR::UUID.default_function = "ulid_with_prefix('myapp')"

# use ulid with a dynamic prefix.
# By default it uses the table name, but you can override it by passing a
# `:prefix` key to `t.primary_key` or `create_table`.
AR::UUID.default_function = "ulid_with_prefix('%{prefix}')"

# use uuid
AR::UUID.default_function = "uuid()"

When you create a new table, the id column will be defined as TEXT, using the defined function as the default value.

create_table :users
add_reference :posts, :users

create_table :posts do |t|
  t.belongs_to :user
  # or
  t.references :user
end

If you need an integer column, specify the type manually.

create_table :users,  do |t|
  t.column :position, :bigserial, null: false
end

Maintainer

  • Nando Vieira

Contributors

Contributing

For more details about how to contribute, please read https://github.com/fnando/ar-sqlite-uuid/blob/main/CONTRIBUTING.md.

License

The gem is available as open source under the terms of the MIT License. A copy of the license can be found at https://github.com/fnando/ar-sqlite-uuid/blob/main/LICENSE.md.

Code of Conduct

Everyone interacting in the ar-sqlite-uuid project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

FAQs

Package last updated on 09 Dec 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.