Class: Jackcess::Index

Inherits:
Object
  • Object
show all
Defined in:
lib/jackcess/index.rb

Overview

Represents an index on a table in an Access database.

Indexes provide fast lookups and enforce uniqueness constraints. This class wraps Jackcess’s Index object to provide a Ruby-friendly interface.

Examples:

Inspect table indexes

table = db.table('Users')
table.indexes.each do |index|
  puts "#{index.name}: #{index.columns.join(', ')}"
  puts "Primary key: #{index.primary_key?}"
  puts "Unique: #{index.unique?}"
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(java_index) ⇒ Index

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Creates a new Index instance wrapping a Java index object.

Parameters:

  • java_index (Java::ComHealthmarketscienceJackcess::Index)

    The Java index object



25
26
27
# File 'lib/jackcess/index.rb', line 25

def initialize(java_index)
  @java_index = java_index
end

Instance Attribute Details

#java_indexJava::ComHealthmarketscienceJackcess::Index (readonly)

The underlying Java index object from Jackcess

Returns:

  • (Java::ComHealthmarketscienceJackcess::Index)


19
20
21
# File 'lib/jackcess/index.rb', line 19

def java_index
  @java_index
end

Instance Method Details

#columnsArray<String>

Returns an array of column names that comprise this index.

Examples:

Get index columns

index.columns # => ["UserID", "Email"]

Returns:

  • (Array<String>)

    Array of column names in the index



45
46
47
# File 'lib/jackcess/index.rb', line 45

def columns
  @java_index.get_columns.map(&:get_name)
end

#ignore_nulls?Boolean

Checks whether this index ignores null values.

When true, null values in indexed columns are not included in the index.

Examples:

Check if nulls are ignored

index.ignore_nulls? # => false

Returns:

  • (Boolean)

    true if null values are ignored, false otherwise



77
78
79
# File 'lib/jackcess/index.rb', line 77

def ignore_nulls?
  @java_index.should_ignore_nulls
end

#inspectObject



81
82
83
# File 'lib/jackcess/index.rb', line 81

def inspect
  "#<Jackcess::Index name=#{name.inspect} columns=#{columns.inspect} primary_key=#{primary_key?}>"
end

#nameString

Returns the name of the index.

Examples:

Get index name

index.name # => "PrimaryKey"

Returns:

  • (String)

    The index name



35
36
37
# File 'lib/jackcess/index.rb', line 35

def name
  @java_index.get_name
end

#primary_key?Boolean

Checks whether this index is the table’s primary key.

Examples:

Check if primary key

index.primary_key? # => true

Returns:

  • (Boolean)

    true if this is a primary key index, false otherwise



55
56
57
# File 'lib/jackcess/index.rb', line 55

def primary_key?
  @java_index.is_primary_key
end

#to_sObject



85
86
87
# File 'lib/jackcess/index.rb', line 85

def to_s
  "#{name}: #{columns.join(', ')}"
end

#unique?Boolean

Checks whether this index enforces uniqueness.

Examples:

Check if unique

index.unique? # => true

Returns:

  • (Boolean)

    true if values in this index must be unique, false otherwise



65
66
67
# File 'lib/jackcess/index.rb', line 65

def unique?
  @java_index.is_unique
end