Page
Library
Module
Module type
Parameter
Class
Class type
Source
Proton.ClientSourceThis module provides the main client interface for connecting to and interacting with Timeplus Proton database servers. It supports query execution, streaming results, and efficient bulk inserts.
type query_result = | NoRowsNo rows returned
*)| Rows of Column.value list list * (string * string) listRows with column metadata
*)Query result type for synchronous query execution.
NoRows indicates the query returned no data (e.g., DDL statements)Rows (data, columns) contains the result rows and column metadataStreaming result container that pairs query results with column metadata. Used by streaming functions that need to return both data and schema information.
The main client type representing a connection to a Proton server. Contains the underlying connection handle used for all database operations.
val create :
?host:string ->
?port:int ->
?database:string ->
?user:string ->
?password:string ->
?tls_config:Connection.tls_config ->
?compression:Protocol.compression ->
?settings:(string * string) list ->
unit ->
tcreate ?host ?port ?database ?user ?password ?tls_config ?compression ?settings () creates a new client connection to a Proton server.
Example:
let client =
Client.create ~host:"proton.example.com" ~port:8463 ~user:"myuser" ~password:"mypass" ()disconnect client gracefully closes the connection to the Proton server.
execute client query executes a SQL query and returns all results at once.
This function is best suited for queries that return a manageable amount of data. For large result sets, consider using the streaming functions instead.
Example:
let%lwt result = Client.execute client "SELECT * FROM events LIMIT 10" in
match result with
| NoRows -> print_endline "No results"
| Rows (data, columns) -> process_results data columnsThese functions provide efficient streaming access to query results, allowing processing of large datasets without loading all data into memory.
val query_fold :
t ->
string ->
init:'acc ->
f:('acc -> Column.value list -> 'acc Lwt.t) ->
'acc Lwt.tquery_fold client query ~init ~f executes a query and folds over the results.
Processes query results incrementally using a fold function, which is memory-efficient for large result sets.
Example:
let%lwt sum =
Client.query_fold client "SELECT value FROM metrics" ~init:0.0 ~f:(fun acc row ->
match row with [ Column.Float v ] -> Lwt.return (acc +. v) | _ -> Lwt.return acc)query_iter client query ~f executes a query and applies a function to each row.
Useful for side-effecting operations on query results without accumulating values.
Example:
Client.query_iter client "SELECT * FROM logs" ~f:(fun row ->
print_row row;
Lwt.return_unit)query_to_seq client query executes a query and returns results as a lazy sequence.
The sequence allows for on-demand processing of results using OCaml's Seq module.
Example:
let%lwt seq = Client.query_to_seq client "SELECT * FROM events" in
let first_10 = Seq.take 10 seq |> List.of_seqquery_collect client query executes a query and collects all results into a list.
Convenience function that loads all query results into memory at once. Use with caution for large result sets.
These functions provide access to both query results and column schema information, useful when the structure of results needs to be examined dynamically.
val query_fold_with_columns :
t ->
string ->
init:'acc ->
f:('acc -> Column.value list -> (string * string) list -> 'acc Lwt.t) ->
'acc streaming_result Lwt.tquery_fold_with_columns client query ~init ~f folds over query results with column metadata.
Similar to query_fold but provides column information to the fold function, allowing schema-aware processing of results.
Example:
let%lwt result =
Client.query_fold_with_columns client "SELECT name, age FROM users" ~init:[]
~f:(fun acc row cols ->
let record = List.combine cols row in
Lwt.return (record :: acc))val query_iter_with_columns :
t ->
string ->
f:(Column.value list -> (string * string) list -> unit Lwt.t) ->
(string * string) list Lwt.tquery_iter_with_columns client query ~f iterates over query results with column metadata.
Applies a function to each row along with column information.
Functions for inserting data into Proton tables, including support for high-performance asynchronous bulk inserts.
val create_async_inserter :
?config:Async_insert.config option ->
t ->
string ->
Async_insert.tcreate_async_inserter ?config client table_name creates an asynchronous bulk inserter.
Creates an inserter that batches inserts for improved performance. The inserter manages its own buffer and flushes data according to the configuration.
Example:
let inserter = Client.create_async_inserter client "events" in
Async_insert.insert inserter row_dataval insert_rows :
t ->
string ->
?columns:(string * string) list ->
Column.value list list ->
unit Lwt.tinsert_rows client table_name ?columns rows performs a synchronous bulk insert.
Inserts multiple rows in a single operation. More efficient than inserting rows individually for batch operations.
Example:
let rows =
[ [ Column.String "event1"; Column.Int 42 ]; [ Column.String "event2"; Column.Int 43 ] ]
in
Client.insert_rows client "events" ~columns:[ ("name", "String"); ("value", "Int32") ] rowsval insert_row :
t ->
string ->
?columns:(string * string) list ->
Column.value list ->
unit Lwt.tinsert_row client table_name ?columns row inserts a single row into a table.
Convenience function for inserting a single row. For multiple rows, use insert_rows or create_async_inserter for better performance.
Example:
Client.insert_row client "events"
~columns:[ ("timestamp", "DateTime"); ("message", "String") ]
[ Column.DateTime (Unix.time ()); Column.String "Application started" ]