Module: BetterAuth::Schema
- Defined in:
- lib/better_auth/schema.rb,
lib/better_auth/schema/sql.rb
Defined Under Namespace
Modules: SQL
Class Method Summary collapse
- .auth_tables(options) ⇒ Object
- .parse_output(options, model, data) ⇒ Object
- .storage_field_name(options, model, field) ⇒ Object
- .storage_key(value) ⇒ Object
- .storage_model_name(options, model) ⇒ Object
Class Method Details
.auth_tables(options) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/better_auth/schema.rb', line 7 def auth_tables() plugin_schema = plugin_tables() tables = { "user" => user_table(, plugin_schema.delete("user")), "session" => session_table(, plugin_schema.delete("session")), "account" => account_table(, plugin_schema.delete("account")), "verification" => verification_table(, plugin_schema.delete("verification")) } tables.delete("session") if secondary_storage?() && !session_option(, :store_session_in_database) tables.merge!(plugin_schema) tables["rateLimit"] = rate_limit_table() if rate_limit_option(, :storage) == "database" tables.sort_by { |_name, table| table[:order] || Float::INFINITY }.to_h end |
.parse_output(options, model, data) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/better_auth/schema.rb', line 34 def parse_output(, model, data) return nil unless data table = auth_tables().fetch(model.to_s) table[:fields].each_with_object({}) do |(field, attributes), result| next if attributes[:returned] == false && field != "id" next unless data.key?(field) result[field] = data[field] end.tap do |result| data.each { |key, value| result[key] = value unless result.key?(key) || table[:fields].key?(key) } end rescue KeyError data end |
.storage_field_name(options, model, field) ⇒ Object
28 29 30 31 32 |
# File 'lib/better_auth/schema.rb', line 28 def storage_field_name(, model, field) table = auth_tables().fetch(model.to_s) data = table[:fields].fetch(field.to_s) data[:field_name] || field.to_s end |
.storage_key(value) ⇒ Object
249 250 251 |
# File 'lib/better_auth/schema.rb', line 249 private_class_method def self.storage_key(value) camelize_lower(value.to_s) end |
.storage_model_name(options, model) ⇒ Object
23 24 25 26 |
# File 'lib/better_auth/schema.rb', line 23 def storage_model_name(, model) table = auth_tables().fetch(model.to_s) table[:model_name] end |