Struct Filemaker

Source
pub struct Filemaker { /* private fields */ }
Expand description

Represents a connection to a Filemaker database with authentication and query capabilities.

This struct manages the connection details and authentication token needed to interact with a Filemaker database through its Data API.

Implementations§

Source§

impl Filemaker

Source

pub async fn new( username: &str, password: &str, database: &str, table: &str, ) -> Result<Self>

Creates a new Filemaker instance.

Initializes a connection to a FileMaker database with the provided credentials. This function performs authentication and sets up the HTTP client with appropriate configuration.

§Arguments
  • username - The username for FileMaker authentication
  • password - The password for FileMaker authentication
  • database - The name of the FileMaker database to connect to
  • table - The name of the table/layout to operate on
§Returns
  • Result<Self> - A new Filemaker instance or an error
Examples found in repository?
examples/filemaker_instance_creation.rs (line 13)
5async fn main() -> Result<()> {
6    std::env::set_var("FM_URL", "https://fm.example.com/fmi/data/vLatest"); // Replace with actual filemaker server url
7    let username = "your_username";
8    let password = "your_password";
9    let database = "your_database";
10    let table = "your_table";
11
12    // Create a Filemaker instance
13    let filemaker = Filemaker::new(username, password, database, table).await?;
14    println!("Filemaker instance created successfully.");
15
16    Ok(())
17}
More examples
Hide additional examples
examples/filemaker_total_records_getter.rs (line 11)
5async fn main() -> Result<()> {
6    std::env::set_var("FM_URL", "https://fm.example.com/fmi/data/vLatest"); // Replace with actual filemaker server url
7    let username = "your_username";
8    let password = "your_password";
9    let database = "your_database";
10    let table = "your_table";
11    let filemaker = Filemaker::new(username, password, database, table).await?;
12
13    // Get the total number of records
14    let total_records = filemaker.get_number_of_records().await?;
15    println!("Total Records: {}", total_records);
16
17    Ok(())
18}
examples/main_filemaker.rs (line 11)
5async fn main() -> Result<()> {
6    std::env::set_var("FM_URL", "https://fm.example.com/fmi/data/vLatest"); // Replace with actual filemaker server url
7    let username = "your_username";
8    let password = "your_password";
9    let database = "your_database";
10    let table = "your_table";
11    let filemaker = Filemaker::new(username, password, database, table).await?;
12
13    // Fetch the first 10 records
14    let records = filemaker.get_records(1, 10).await?;
15    println!("Fetched Records:");
16    for record in records {
17        println!("{:?}", record);
18    }
19
20    Ok(())
21}
examples/filemaker_record_deleter.rs (line 11)
5async fn main() -> Result<()> {
6    std::env::set_var("FM_URL", "https://fm.example.com/fmi/data/vLatest"); // Replace with actual filemaker server url
7    let username = "your_username";
8    let password = "your_password";
9    let database = "your_database";
10    let table = "your_table";
11    let filemaker = Filemaker::new(username, password, database, table).await?;
12
13    // Record ID to delete
14    let record_id = 123; // Replace with the actual record ID
15
16    // Delete the record
17    let result = filemaker.delete_record(record_id).await?;
18    println!("Record deleted successfully: {:?}", result);
19
20    Ok(())
21}
examples/filemaker_single_record_adder.rs (line 8)
6async fn main() -> Result<(), anyhow::Error> {
7    // Initialize the Filemaker instance
8    let filemaker = Filemaker::new("username", "password", "database_name", "table_name").await?;
9
10    // Create the field data for a single record
11    let mut single_record_data = HashMap::new();
12    single_record_data.insert("field_name1".to_string(), Value::String("Value 1".to_string()));
13    single_record_data.insert("field_name2".to_string(), Value::String("Value 2".to_string()));
14
15    // Add the single record
16    let result = filemaker.add_record(single_record_data).await?;
17
18    // Print the result
19    println!("Single record added: {:?}", result);
20
21    Ok(())
22}
examples/filemaker_record_updater.rs (line 13)
7async fn main() -> Result<()> {
8    std::env::set_var("FM_URL", "https://fm.example.com/fmi/data/vLatest"); // Replace with actual filemaker server url
9    let username = "your_username";
10    let password = "your_password";
11    let database = "your_database";
12    let table = "your_table";
13    let filemaker = Filemaker::new(username, password, database, table).await?;
14
15    // Record ID to update
16    let record_id = 123; // Replace with the actual record ID
17
18    // Data to update
19    let mut field_data = HashMap::new();
20    field_data.insert("fieldName".to_string(), Value::String("new_value".to_string())); // Replace "fieldName" and "new_value"
21
22    // Update the record
23    let result = filemaker.update_record(record_id, field_data).await?;
24    println!("Update Result: {:?}", result);
25
26    Ok(())
27}
Source

pub async fn get_records<T>(&self, start: T, limit: T) -> Result<Vec<Value>>
where T: Sized + Clone + Display + FromStr + TryFrom<usize>,

Retrieves a specified range of records from the database.

§Arguments
  • start - The starting position (offset) for record retrieval
  • limit - The maximum number of records to retrieve
§Returns
  • Result<Vec<Value>> - A vector of record objects on success, or an error
Examples found in repository?
examples/main_filemaker.rs (line 14)
5async fn main() -> Result<()> {
6    std::env::set_var("FM_URL", "https://fm.example.com/fmi/data/vLatest"); // Replace with actual filemaker server url
7    let username = "your_username";
8    let password = "your_password";
9    let database = "your_database";
10    let table = "your_table";
11    let filemaker = Filemaker::new(username, password, database, table).await?;
12
13    // Fetch the first 10 records
14    let records = filemaker.get_records(1, 10).await?;
15    println!("Fetched Records:");
16    for record in records {
17        println!("{:?}", record);
18    }
19
20    Ok(())
21}
Source

pub async fn get_all_records(&self) -> Result<Vec<Value>>

Retrieves all records from the database in a single query.

This method first determines the total record count and then fetches all records in a single request.

§Returns
  • Result<Vec<Value>> - A vector containing all records on success, or an error
Source

pub async fn get_number_of_records(&self) -> Result<u64>

Retrieves the total number of records in the database table.

§Returns
  • Result<u64> - The total record count on success, or an error
Examples found in repository?
examples/filemaker_total_records_getter.rs (line 14)
5async fn main() -> Result<()> {
6    std::env::set_var("FM_URL", "https://fm.example.com/fmi/data/vLatest"); // Replace with actual filemaker server url
7    let username = "your_username";
8    let password = "your_password";
9    let database = "your_database";
10    let table = "your_table";
11    let filemaker = Filemaker::new(username, password, database, table).await?;
12
13    // Get the total number of records
14    let total_records = filemaker.get_number_of_records().await?;
15    println!("Total Records: {}", total_records);
16
17    Ok(())
18}
Source

pub async fn search<T>( &self, query: Vec<HashMap<String, String>>, sort: Vec<String>, ascending: bool, limit: Option<u64>, ) -> Result<FindResult<T>>

Searches the database for records matching specified criteria.

§Arguments
  • query - Vector of field-value pairs to search for
  • sort - Vector of field names to sort by
  • ascending - Whether to sort in ascending (true) or descending (false) order
  • limit - If None, all results will be returned; otherwise, the specified limit will be applied
§Returns
  • Result<Vec<T>> - A vector of matching records as the specified type on success, or an error
Examples found in repository?
examples/filemaker_search_results_output.rs (line 24)
7async fn main() -> Result<()> {
8    std::env::set_var("FM_URL", "https://fm.example.com/fmi/data/vLatest"); // Replace with actual filemaker server url
9    let username = "your_username";
10    let password = "your_password";
11    let database = "your_database";
12    let table = "your_table";
13    let filemaker = Filemaker::new(username, password, database, table).await?;
14
15    // Construct search query
16    let mut query = HashMap::new();
17    query.insert("fieldName".to_string(), "example_value".to_string()); // Replace "fieldName" and "example_value"
18
19    // Sorting criteria
20    let sort_fields = vec!["fieldName".to_string()]; // Replace with the field name to sort
21    let ascending = true;
22
23    let records = filemaker
24        .search::<Value>(vec![query], sort_fields, ascending, Some(10))
25        .await?;
26    println!("Search Results:");
27    for record in records.response.data {
28        println!("{:?}", record);
29    }
30
31    Ok(())
32}
Source

pub async fn add_record( &self, field_data: HashMap<String, Value>, ) -> Result<HashMap<String, Value>>

Adds a record to the database.

§Parameters
  • field_data: A HashMap representing the field data for the new record.
§Returns

A Result containing the added record as a Value on success, or an error.

Examples found in repository?
examples/filemaker_single_record_adder.rs (line 16)
6async fn main() -> Result<(), anyhow::Error> {
7    // Initialize the Filemaker instance
8    let filemaker = Filemaker::new("username", "password", "database_name", "table_name").await?;
9
10    // Create the field data for a single record
11    let mut single_record_data = HashMap::new();
12    single_record_data.insert("field_name1".to_string(), Value::String("Value 1".to_string()));
13    single_record_data.insert("field_name2".to_string(), Value::String("Value 2".to_string()));
14
15    // Add the single record
16    let result = filemaker.add_record(single_record_data).await?;
17
18    // Print the result
19    println!("Single record added: {:?}", result);
20
21    Ok(())
22}
More examples
Hide additional examples
examples/filemaker_multiple_record_adder.rs (line 28)
6async fn main() -> Result<(), anyhow::Error> {
7    // Initialize the Filemaker instance
8    let filemaker = Filemaker::new("username", "password", "database_name", "table_name").await?;
9
10    // Prepare data for multiple records
11    let records = vec![
12        {
13            let mut record = HashMap::new();
14            record.insert("field_name1".to_string(), Value::String("First Record - Value 1".to_string()));
15            record.insert("field_name2".to_string(), Value::String("First Record - Value 2".to_string()));
16            record
17        },
18        {
19            let mut record = HashMap::new();
20            record.insert("field_name1".to_string(), Value::String("Second Record - Value 1".to_string()));
21            record.insert("field_name2".to_string(), Value::String("Second Record - Value 2".to_string()));
22            record
23        },
24    ];
25
26    // Add each record to the database
27    for (i, record_data) in records.into_iter().enumerate() {
28        match filemaker.add_record(record_data).await {
29            Ok(result) => println!("Record {} added successfully: {:?}", i + 1, result),
30            Err(e) => eprintln!("Failed to add record {}: {}", i + 1, e),
31        }
32    }
33
34    Ok(())
35}
Source

pub async fn update_record<T>( &self, id: T, field_data: HashMap<String, Value>, ) -> Result<Value>
where T: Sized + Clone + Display + FromStr + TryFrom<usize>,

Updates a record in the database using the FileMaker Data API.

§Arguments
  • id - The unique identifier of the record to update
  • field_data - A hashmap containing the field names and their new values
§Returns
  • Result<Value> - The server response as a JSON value or an error
§Type Parameters
  • T - A type that can be used as a record identifier and meets various trait requirements
Examples found in repository?
examples/filemaker_record_updater.rs (line 23)
7async fn main() -> Result<()> {
8    std::env::set_var("FM_URL", "https://fm.example.com/fmi/data/vLatest"); // Replace with actual filemaker server url
9    let username = "your_username";
10    let password = "your_password";
11    let database = "your_database";
12    let table = "your_table";
13    let filemaker = Filemaker::new(username, password, database, table).await?;
14
15    // Record ID to update
16    let record_id = 123; // Replace with the actual record ID
17
18    // Data to update
19    let mut field_data = HashMap::new();
20    field_data.insert("fieldName".to_string(), Value::String("new_value".to_string())); // Replace "fieldName" and "new_value"
21
22    // Update the record
23    let result = filemaker.update_record(record_id, field_data).await?;
24    println!("Update Result: {:?}", result);
25
26    Ok(())
27}
Source

pub async fn get_databases( username: &str, password: &str, ) -> Result<Vec<String>>

Retrieves the list of databases accessible to the specified user.

§Arguments
  • username - The FileMaker username for authentication
  • password - The FileMaker password for authentication
§Returns
  • Result<Vec<String>> - A list of accessible database names or an error
Examples found in repository?
examples/get_databases.rs (line 9)
5async fn main()->Result<()> {
6	std::env::set_var("FM_URL", "https://fm.example.com/fmi/data/vLatest"); // Replace with actual filemaker server url
7	let username = "username"; // Replace with actual username
8	let password = "password"; // Replace with actual password
9	let databases = Filemaker::get_databases(username, password).await?;
10	for db in databases {
11		println!("{}", db);
12	}
13	
14	Ok(())
15}
More examples
Hide additional examples
examples/fetch_databases_list.rs (line 11)
5async fn main() -> Result<()> {
6    std::env::set_var("FM_URL", "https://fm.example.com/fmi/data/vLatest"); // Replace with actual filemaker server url
7    let username = "your_username";
8    let password = "your_password";
9
10    // Fetch the list of databases
11    let databases = Filemaker::get_databases(username, password).await?;
12    println!("Databases:");
13    for db in databases {
14        println!("{}", db);
15    }
16
17    Ok(())
18}
Source

pub async fn get_layouts( username: &str, password: &str, database: &str, ) -> Result<Vec<String>>

Retrieves the list of layouts for the specified database using the provided credentials.

§Arguments
  • username - The FileMaker username for authentication
  • password - The FileMaker password for authentication
  • database - The name of the database to get layouts from
§Returns
  • Result<Vec<String>> - A list of layout names or an error
Examples found in repository?
examples/filemaker_layout_fetcher.rs (line 12)
5async fn main() -> Result<()> {
6    std::env::set_var("FM_URL", "https://fm.example.com/fmi/data/vLatest"); // Replace with actual filemaker server url
7    let username = "your_username";
8    let password = "your_password";
9    let database = "your_database";
10
11    // Fetch layouts
12    let layouts = Filemaker::get_layouts(username, password, database).await?;
13    println!("Available Layouts:");
14    for layout in layouts {
15        println!("{}", layout);
16    }
17
18    Ok(())
19}
Source

pub async fn get_record_by_id<T>(&self, id: T) -> Result<Value>
where T: Sized + Clone + Display + FromStr + TryFrom<usize>,

Gets a record from the database by its ID.

§Arguments
  • id - The ID of the record to get.
§Returns

A JSON object representing the record.

Source

pub async fn delete_record<T>(&self, id: T) -> Result<Value>
where T: Sized + Clone + Display + FromStr + TryFrom<usize>,

Deletes a record from the database by its ID.

§Arguments
  • id - The ID of the record to delete.
§Returns

A result indicating the deletion was successful or an error message.

Examples found in repository?
examples/filemaker_record_deleter.rs (line 17)
5async fn main() -> Result<()> {
6    std::env::set_var("FM_URL", "https://fm.example.com/fmi/data/vLatest"); // Replace with actual filemaker server url
7    let username = "your_username";
8    let password = "your_password";
9    let database = "your_database";
10    let table = "your_table";
11    let filemaker = Filemaker::new(username, password, database, table).await?;
12
13    // Record ID to delete
14    let record_id = 123; // Replace with the actual record ID
15
16    // Delete the record
17    let result = filemaker.delete_record(record_id).await?;
18    println!("Record deleted successfully: {:?}", result);
19
20    Ok(())
21}
Source

pub async fn delete_database( database: &str, username: &str, password: &str, ) -> Result<()>

Deletes the specified database.

§Arguments
  • database - The name of the database to delete.
  • username - The username for authentication.
  • password - The password for authentication.
Source

pub async fn clear_database(&self) -> Result<()>

Deletes all records from the current database.

This function retrieves and systematically removes all records from the database. It first checks if there are any records to delete, then proceeds with deletion if records exist.

§Returns
  • Result<()> - Ok(()) if all records were successfully deleted, or an error
§Errors
  • Returns error if unable to retrieve records
  • Returns error if record ID parsing fails
  • Returns error if record deletion fails
Source

pub fn get_row_names_by_example(record: &Value) -> Vec<String>

Returns the names of fields in the given record excluding the ones starting with ‘g_’ (global fields)

§Arguments
  • record - An example record with ‘fieldData’ element containing field names as keys.
§Returns

An array of field names.

Source

pub async fn get_row_names(&self) -> Result<Vec<String>>

Gets the field names for the first record in the database.

This function retrieves a single record from the database and extracts field names from it. If no records exist, an empty vector is returned.

§Returns
  • Result<Vec<String>> - A vector of field names on success, or an error

Searches the database for records matching the specified query.

§Arguments
  • fields - The query fields.
  • sort - The sort order.
  • ascending - Whether to sort in ascending order.
§Returns

A vector of matching records.

Trait Implementations§

Source§

impl Clone for Filemaker

Source§

fn clone(&self) -> Filemaker

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,