EctoLibSql.Result (EctoLibSql v0.8.8)

Copy Markdown View Source

Represents the result of a database query or command.

This struct contains all information returned from a successful database operation, including column names, result rows, and metadata about the operation performed.

Fields

  • :command - The type of SQL command (:select, :insert, :update, :delete, :create, :begin, :commit, :rollback, :pragma, :batch, :unknown, :other, or nil)
  • :columns - List of column names (for SELECT queries), or nil for write operations
  • :rows - List of rows, where each row is a list of values, or nil for write operations
  • :num_rows - Number of rows affected or returned

Examples

# SELECT result
%EctoLibSql.Result{
  command: :select,
  columns: ["id", "name"],
  rows: [[1, "Alice"], [2, "Bob"]],
  num_rows: 2
}

# INSERT/UPDATE/DELETE result (without RETURNING)
%EctoLibSql.Result{
  command: :insert,
  columns: nil,
  rows: nil,
  num_rows: 1
}

Summary

Types

The type of SQL command that was executed.

t()

Result struct containing query results.

Functions

Creates a new Result struct from a keyword list of options.

Types

command_type()

@type command_type() ::
  :select
  | :insert
  | :update
  | :delete
  | :batch
  | :create
  | :begin
  | :commit
  | :rollback
  | :pragma
  | :unknown
  | :other
  | nil

The type of SQL command that was executed.

t()

@type t() :: %EctoLibSql.Result{
  columns: [String.t()] | nil,
  command: command_type(),
  num_rows: non_neg_integer(),
  rows: [[term()]] | nil
}

Result struct containing query results.

Functions

new(options)

@spec new(Keyword.t()) :: t()

Creates a new Result struct from a keyword list of options.

Options

  • :command - The command type (default: :other)
  • :columns - List of column names (default: nil)
  • :rows - List of rows (default: nil)
  • :num_rows - Number of rows (default: 0)

Examples

iex> EctoLibSql.Result.new(command: :select, columns: ["id"], rows: [[1]], num_rows: 1)
%EctoLibSql.Result{command: :select, columns: ["id"], rows: [[1]], num_rows: 1}