Class: Cloudflare::D1::Model

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/cloudflare/d1/model.rb

Overview

Base class for D1-backed ActiveRecord models

Example usage:

class User < Cloudflare::D1::Model
# Automatically uses D1 database named "users" (inferred from table_name)
end

# Configure in database.yml:
# production:
#   adapter: cloudflare_d1
#   account_id: <%= ENV['CLOUDFLARE_ACCOUNT_ID'] %>
#   api_token: <%= ENV['CLOUDFLARE_API_TOKEN'] %>
#   database_id: users_db_uuid

Class Method Summary collapse

Class Method Details

.cloudflare_account_idString

Returns the Cloudflare account ID from the connection configuration

Returns:

  • (String)

    The account ID



40
41
42
# File 'lib/cloudflare/d1/model.rb', line 40

def 
  connection_db_config.configuration_hash[:account_id]
end

.d1_database_idString

Returns the D1 database ID from the connection configuration

Returns:

  • (String)

    The database UUID



34
35
36
# File 'lib/cloudflare/d1/model.rb', line 34

def d1_database_id
  connection_db_config.configuration_hash[:database_id]
end

.d1_database_nameString

Returns the D1 database name inferred from the table name

Returns:

  • (String)

    The database name



28
29
30
# File 'lib/cloudflare/d1/model.rb', line 28

def d1_database_name
  table_name
end