Class: Sequel::DuckDB::Dataset

Inherits:
Sequel::Dataset
  • Object
show all
Includes:
DatasetMethods
Defined in:
lib/sequel/adapters/duckdb.rb

Overview

Dataset class for DuckDB adapter

This class extends Sequel::Dataset to provide DuckDB-specific SQL generation and query execution functionality. It includes DatasetMethods from the shared module for SQL generation and other dataset operations.

The Dataset class is responsible for:

  • Generating DuckDB-compatible SQL for all operations (SELECT, INSERT, UPDATE, DELETE)
  • Executing queries against DuckDB databases
  • Handling result set processing and type conversion
  • Supporting DuckDB-specific features like window functions and CTEs

Examples:

Basic queries

users = db[:users]
users.where(active: true).all
users.where { age > 25 }.count
users.order(:name).limit(10).each { |user| puts user[:name] }

Analytical queries with DuckDB features

# Window functions
db[:sales].select(
  :product_id,
  :amount,
  Sequel.function(:rank).over(partition: :category, order: Sequel.desc(:amount)).as(:rank)
)

# Common Table Expressions (CTEs)
db.with(:high_spenders,
  db[:orders].group(:user_id).having { sum(:total) > 1000 }.select(:user_id)
).from(:high_spenders).join(:users, id: :user_id)

Data modification

# Insert single record
users.insert(name: 'John', email: '[email protected]', age: 30)

# Bulk insert
users.multi_insert([
  {name: 'Alice', email: '[email protected]'},
  {name: 'Bob', email: '[email protected]'}
])

# Update records
users.where(active: false).update(active: true, updated_at: Time.now)

# Delete records
users.where { created_at < Date.today - 365 }.delete

See Also:

Since:

  • 0.1.0

Constant Summary

Constants included from DatasetMethods

Sequel::DuckDB::DatasetMethods::DUCKDB_RESERVED_WORDS

Method Summary

Methods included from DatasetMethods

#add_index_hints, #add_parallel_hints, #all, #analyze_query, #bulk_insert_optimized, #complex_expression_sql_append, #convert_row_types, #count, #cte_is_recursive?, #delete, #delete_sql, #each, #explain, #extract_indexes_from_plan, #fetch_rows, #generate_optimization_hints, #group, #identifier_needs_quoting?, #input_identifier, #insert, #insert_sql, #join, #literal_append, #literal_blob, #literal_blob_append, #literal_boolean, #literal_date, #literal_datetime, #literal_datetime_append, #literal_false, #literal_string_append, #literal_symbol_append, #literal_time, #literal_true, #memory_usage, #multi_insert, #optimize_for_columnar_projection, #optimize_for_result_size, #order, #order_column_sql, #output_identifier, #parallel, #prepare, #quote_identifiers_default, #reserved_word?, #select, #select_from_sql, #select_group_sql, #select_having_sql, #select_join_sql, #select_order_sql, #select_where_sql, #select_with_sql, #should_use_bulk_operations?, #should_use_parallel_execution?, #single_value, #stream, #stream_batch_size, #stream_with_memory_limit, #supports_cte?, #supports_join_using?, #supports_returning?, #supports_select_all_and_offset?, #supports_window_functions?, #table_name_sql, #table_schema_for_conversion, #update, #update_sql, #validate_table_name_for_select, #where, #with_connection_pooling