Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions gems/activerecord/6.0/activerecord-6.0.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,26 @@ module ActiveRecord
class MismatchedForeignKey < StatementInvalid
def initialize: (?primary_key_column: untyped? primary_key_column, ?primary_key: untyped? primary_key, ?target_table: untyped? target_table, ?foreign_key: untyped? foreign_key, ?table: untyped? table, ?binds: untyped? binds, ?sql: untyped? sql, ?message: untyped? message) -> untyped
end

module Persistence
extend ActiveSupport::Concern

module ClassMethods
def insert: (untyped attributes, ?unique_by: untyped?, ?returning: untyped?) -> untyped

def insert_all: (untyped attributes, ?unique_by: untyped?, ?returning: untyped?) -> untyped

def insert!: (untyped attributes, ?returning: untyped?) -> untyped

def insert_all!: (untyped attributes, ?returning: untyped?) -> untyped

def upsert: (untyped attributes, ?unique_by: untyped?, ?returning: untyped?) -> untyped

def upsert_all: (untyped attributes, ?unique_by: untyped?, ?returning: untyped?) -> untyped
end
end

class InsertAll
def initialize: (untyped model, untyped inserts, on_duplicate: untyped, ?unique_by: untyped?, ?returning: untyped?) -> untyped
end
end
176 changes: 0 additions & 176 deletions gems/activerecord/6.0/activerecord-generated.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -13804,8 +13804,6 @@ module ActiveRecord

attr_reader unique_by: untyped

def initialize: (untyped model, untyped inserts, on_duplicate: untyped on_duplicate, ?unique_by: untyped? unique_by, ?returning: untyped? returning) -> untyped

def execute: () -> untyped

def updatable_columns: () -> untyped
Expand Down Expand Up @@ -16187,180 +16185,6 @@ module ActiveRecord
# multiple objects when given an Array of Hashes.
def create!: (?untyped? attributes) ?{ () -> untyped } -> untyped

# Inserts a single record into the database in a single SQL INSERT
# statement. It does not instantiate any models nor does it trigger
# Active Record callbacks or validations. Though passed values
# go through Active Record's type casting and serialization.
#
# See <tt>ActiveRecord::Persistence#insert_all</tt> for documentation.
def insert: (untyped attributes, ?unique_by: untyped? unique_by, ?returning: untyped? returning) -> untyped

# Inserts multiple records into the database in a single SQL INSERT
# statement. It does not instantiate any models nor does it trigger
# Active Record callbacks or validations. Though passed values
# go through Active Record's type casting and serialization.
#
# The +attributes+ parameter is an Array of Hashes. Every Hash determines
# the attributes for a single row and must have the same keys.
#
# Rows are considered to be unique by every unique index on the table. Any
# duplicate rows are skipped.
# Override with <tt>:unique_by</tt> (see below).
#
# Returns an <tt>ActiveRecord::Result</tt> with its contents based on
# <tt>:returning</tt> (see below).
#
# ==== Options
#
# [:returning]
# (PostgreSQL only) An array of attributes to return for all successfully
# inserted records, which by default is the primary key.
# Pass <tt>returning: %w[ id name ]</tt> for both id and name
# or <tt>returning: false</tt> to omit the underlying <tt>RETURNING</tt> SQL
# clause entirely.
#
# [:unique_by]
# (PostgreSQL and SQLite only) By default rows are considered to be unique
# by every unique index on the table. Any duplicate rows are skipped.
#
# To skip rows according to just one unique index pass <tt>:unique_by</tt>.
#
# Consider a Book model where no duplicate ISBNs make sense, but if any
# row has an existing id, or is not unique by another unique index,
# <tt>ActiveRecord::RecordNotUnique</tt> is raised.
#
# Unique indexes can be identified by columns or name:
#
# unique_by: :isbn
# unique_by: %i[ author_id name ]
# unique_by: :index_books_on_isbn
#
# Because it relies on the index information from the database
# <tt>:unique_by</tt> is recommended to be paired with
# Active Record's schema_cache.
#
# ==== Example
#
# # Insert records and skip inserting any duplicates.
# # Here "Eloquent Ruby" is skipped because its id is not unique.
#
# Book.insert_all([
# { id: 1, title: "Rework", author: "David" },
# { id: 1, title: "Eloquent Ruby", author: "Russ" }
# ])
def insert_all: (untyped attributes, ?unique_by: untyped? unique_by, ?returning: untyped? returning) -> untyped

# Inserts a single record into the database in a single SQL INSERT
# statement. It does not instantiate any models nor does it trigger
# Active Record callbacks or validations. Though passed values
# go through Active Record's type casting and serialization.
#
# See <tt>ActiveRecord::Persistence#insert_all!</tt> for more.
def insert!: (untyped attributes, ?returning: untyped? returning) -> untyped

# Inserts multiple records into the database in a single SQL INSERT
# statement. It does not instantiate any models nor does it trigger
# Active Record callbacks or validations. Though passed values
# go through Active Record's type casting and serialization.
#
# The +attributes+ parameter is an Array of Hashes. Every Hash determines
# the attributes for a single row and must have the same keys.
#
# Raises <tt>ActiveRecord::RecordNotUnique</tt> if any rows violate a
# unique index on the table. In that case, no rows are inserted.
#
# To skip duplicate rows, see <tt>ActiveRecord::Persistence#insert_all</tt>.
# To replace them, see <tt>ActiveRecord::Persistence#upsert_all</tt>.
#
# Returns an <tt>ActiveRecord::Result</tt> with its contents based on
# <tt>:returning</tt> (see below).
#
# ==== Options
#
# [:returning]
# (PostgreSQL only) An array of attributes to return for all successfully
# inserted records, which by default is the primary key.
# Pass <tt>returning: %w[ id name ]</tt> for both id and name
# or <tt>returning: false</tt> to omit the underlying <tt>RETURNING</tt> SQL
# clause entirely.
#
# ==== Examples
#
# # Insert multiple records
# Book.insert_all!([
# { title: "Rework", author: "David" },
# { title: "Eloquent Ruby", author: "Russ" }
# ])
#
# # Raises ActiveRecord::RecordNotUnique because "Eloquent Ruby"
# # does not have a unique id.
# Book.insert_all!([
# { id: 1, title: "Rework", author: "David" },
# { id: 1, title: "Eloquent Ruby", author: "Russ" }
# ])
def insert_all!: (untyped attributes, ?returning: untyped? returning) -> untyped

# Updates or inserts (upserts) a single record into the database in a
# single SQL INSERT statement. It does not instantiate any models nor does
# it trigger Active Record callbacks or validations. Though passed values
# go through Active Record's type casting and serialization.
#
# See <tt>ActiveRecord::Persistence#upsert_all</tt> for documentation.
def upsert: (untyped attributes, ?unique_by: untyped? unique_by, ?returning: untyped? returning) -> untyped

# Updates or inserts (upserts) multiple records into the database in a
# single SQL INSERT statement. It does not instantiate any models nor does
# it trigger Active Record callbacks or validations. Though passed values
# go through Active Record's type casting and serialization.
#
# The +attributes+ parameter is an Array of Hashes. Every Hash determines
# the attributes for a single row and must have the same keys.
#
# Returns an <tt>ActiveRecord::Result</tt> with its contents based on
# <tt>:returning</tt> (see below).
#
# ==== Options
#
# [:returning]
# (PostgreSQL only) An array of attributes to return for all successfully
# inserted records, which by default is the primary key.
# Pass <tt>returning: %w[ id name ]</tt> for both id and name
# or <tt>returning: false</tt> to omit the underlying <tt>RETURNING</tt> SQL
# clause entirely.
#
# [:unique_by]
# (PostgreSQL and SQLite only) By default rows are considered to be unique
# by every unique index on the table. Any duplicate rows are skipped.
#
# To skip rows according to just one unique index pass <tt>:unique_by</tt>.
#
# Consider a Book model where no duplicate ISBNs make sense, but if any
# row has an existing id, or is not unique by another unique index,
# <tt>ActiveRecord::RecordNotUnique</tt> is raised.
#
# Unique indexes can be identified by columns or name:
#
# unique_by: :isbn
# unique_by: %i[ author_id name ]
# unique_by: :index_books_on_isbn
#
# Because it relies on the index information from the database
# <tt>:unique_by</tt> is recommended to be paired with
# Active Record's schema_cache.
#
# ==== Examples
#
# # Inserts multiple records, performing an upsert when records have duplicate ISBNs.
# # Here "Eloquent Ruby" overwrites "Rework" because its ISBN is duplicate.
#
# Book.upsert_all([
# { title: "Rework", author: "David", isbn: "1" },
# { title: "Eloquent Ruby", author: "Russ", isbn: "1" }
# ], unique_by: :isbn)
#
# Book.find_by(isbn: "1").title # => "Eloquent Ruby"
def upsert_all: (untyped attributes, ?unique_by: untyped? unique_by, ?returning: untyped? returning) -> untyped

# Given an attributes hash, +instantiate+ returns a new instance of
# the appropriate class. Accepts only keys as strings.
#
Expand Down
22 changes: 22 additions & 0 deletions gems/activerecord/6.1/activerecord-6.1.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,26 @@ module ActiveRecord
def missing: (*Symbol associations) -> Relation
end
end

module Persistence
extend ActiveSupport::Concern

module ClassMethods
def insert: (untyped attributes, ?unique_by: untyped?, ?returning: untyped?) -> untyped

def insert_all: (untyped attributes, ?unique_by: untyped?, ?returning: untyped?) -> untyped

def insert!: (untyped attributes, ?returning: untyped?) -> untyped

def insert_all!: (untyped attributes, ?returning: untyped?) -> untyped

def upsert: (untyped attributes, ?unique_by: untyped?, ?returning: untyped?) -> untyped

def upsert_all: (untyped attributes, ?unique_by: untyped?, ?returning: untyped?) -> untyped
end
end

class InsertAll
def initialize: (untyped model, untyped inserts, on_duplicate: untyped, ?unique_by: untyped?, ?returning: untyped?) -> untyped
end
end
6 changes: 6 additions & 0 deletions gems/activerecord/7.0/_test/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ class User < ApplicationRecord
User.where.missing.to_sql
User.deterministic_encrypted_attributes
User.source_attribute_from_preserved_attribute(:phrase)
User.insert({ id: 1, name: 'James' }, returning: %i[id name], unique_by: :id, record_timestamps: true)
User.insert!({ id: 1, name: 'James' }, returning: %i[id name], record_timestamps: true)
User.insert_all([{ id: 1, name: 'James' }], returning: %i[id name], unique_by: :id, record_timestamps: true)
User.insert_all!([{ id: 1, name: 'James' }], returning: %i[id name], record_timestamps: true)
User.upsert({ id: 1, name: 'James' }, returning: %i[id name], unique_by: :id, record_timestamps: true)
User.upsert_all([{ id: 1, name: 'James' }], returning: %i[id name], unique_by: :id, record_timestamps: true)
user = User.new(secret: 'dummy', key: 'dummy', token: 'dummy', phrase: 'dummy')
user.encrypt
user.encrypted_attribute?(:secret)
Expand Down
30 changes: 30 additions & 0 deletions gems/activerecord/7.0/activerecord-7.0.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,34 @@ module ActiveRecord
class MismatchedForeignKey < StatementInvalid
def initialize: (?primary_key_column: untyped? primary_key_column, ?primary_key: untyped? primary_key, ?target_table: untyped? target_table, ?foreign_key: untyped? foreign_key, ?table: untyped? table, ?binds: untyped? binds, ?sql: untyped? sql, ?message: untyped? message) -> untyped
end

module Persistence
extend ActiveSupport::Concern

module ClassMethods
def insert: (untyped attributes, ?unique_by: untyped?, ?returning: untyped?, ?record_timestamps: bool?) -> untyped

def insert_all: (untyped attributes, ?unique_by: untyped?, ?returning: untyped?, ?record_timestamps: bool?) -> untyped

def insert!: (untyped attributes, ?returning: untyped?, ?record_timestamps: bool?) -> untyped

def insert_all!: (untyped attributes, ?returning: untyped?, ?record_timestamps: bool?) -> untyped

def upsert: (untyped attributes, ?unique_by: untyped?, ?returning: untyped?, ?record_timestamps: bool?) -> untyped

def upsert_all: (untyped attributes, ?unique_by: untyped?, ?returning: untyped?, ?record_timestamps: bool?) -> untyped
end
end

class InsertAll
@record_timestamps: bool

def initialize: (untyped model, untyped inserts, on_duplicate: untyped, ?unique_by: untyped?, ?returning: untyped?, ?record_timestamps: bool?) -> untyped

def record_timestamps?: () -> bool

def keys_including_timestamps: () -> Set[String]

def timestamps_for_create: () -> Hash[String, String]
end
end
6 changes: 6 additions & 0 deletions gems/activerecord/7.1/_test/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ class User < ApplicationRecord
User.where.missing.to_sql
User.deterministic_encrypted_attributes
User.source_attribute_from_preserved_attribute(:phrase)
User.insert({ id: 1, name: 'James' }, returning: %i[id name], unique_by: :id, record_timestamps: true)
User.insert!({ id: 1, name: 'James' }, returning: %i[id name], record_timestamps: true)
User.insert_all([{ id: 1, name: 'James' }], returning: %i[id name], unique_by: :id, record_timestamps: true)
User.insert_all!([{ id: 1, name: 'James' }], returning: %i[id name], record_timestamps: true)
User.upsert({ id: 1, name: 'James' }, returning: %i[id name], unique_by: :id, record_timestamps: true)
User.upsert_all([{ id: 1, name: 'James' }], returning: %i[id name], unique_by: :id, record_timestamps: true)
user = User.new(secret: 'dummy', key: 'dummy', token: 'dummy', phrase: 'dummy')
user.encrypt
user.encrypted_attribute?(:secret)
Expand Down
30 changes: 30 additions & 0 deletions gems/activerecord/7.1/activerecord-7.1.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,34 @@ module ActiveRecord
?primary_key_column: untyped?, ?query_parser: untyped?,
?connection_pool: ConnectionAdapters::ConnectionPool?) -> void
end

module Persistence
extend ActiveSupport::Concern

module ClassMethods
def insert: (untyped attributes, ?unique_by: untyped?, ?returning: untyped?, ?record_timestamps: bool?) -> untyped

def insert_all: (untyped attributes, ?unique_by: untyped?, ?returning: untyped?, ?record_timestamps: bool?) -> untyped

def insert!: (untyped attributes, ?returning: untyped?, ?record_timestamps: bool?) -> untyped

def insert_all!: (untyped attributes, ?returning: untyped?, ?record_timestamps: bool?) -> untyped

def upsert: (untyped attributes, ?unique_by: untyped?, ?returning: untyped?, ?record_timestamps: bool?) -> untyped

def upsert_all: (untyped attributes, ?unique_by: untyped?, ?returning: untyped?, ?record_timestamps: bool?) -> untyped
end
end

class InsertAll
@record_timestamps: bool

def initialize: (untyped model, untyped inserts, on_duplicate: untyped, ?unique_by: untyped?, ?returning: untyped?, ?record_timestamps: bool?) -> untyped

def record_timestamps?: () -> bool

def keys_including_timestamps: () -> Set[String]

def timestamps_for_create: () -> Hash[String, String]
end
end