| Crates.io | filemaker-lib |
| lib.rs | filemaker-lib |
| version | 0.2.0 |
| created_at | 2025-03-24 13:51:34.899969+00 |
| updated_at | 2025-09-10 14:07:02.776975+00 |
| description | A library for interacting with a filemaker api |
| homepage | |
| repository | https://github.com/Drew-Chase/filemaker-lib |
| max_upload_size | |
| id | 1603808 |
| size | 137,312 |
This project is a Rust library (filemaker-lib) designed to interact with the FileMaker Data API. It provides a simple API to perform key operations against FileMaker databases, such as fetching records, performing searches, updating records, deleting records, and manipulating database sessions.
Add filemaker-lib to your project's Cargo.toml:
[dependencies]
filemaker-lib = "0.2.0"
or using git
[dependencies]
filemaker-lib = {git = "https://github.com/Drew-Chase/filemaker-lib.git"}
To create a Filemaker instance, you need to pass valid credentials (username and password), the name of the database, and the table you want to work with:
use filemaker_lib::Filemaker;
use anyhow::Result;
#[tokio::main]
async fn main() -> Result<()> {
Filemaker::set_fm_url("https://fm.example.com/fmi/data/vLatest")?; // Replace with actual FileMaker server URL
let username = "your_username";
let password = "your_password";
let database = "your_database";
let table = "your_table";
let filemaker = Filemaker::new(username, password, database, table).await?;
println!("Filemaker instance created successfully.");
Ok(())
}
The library uses the FM_URL environment variable to specify the base URL of the FileMaker server. You need to set this variable before using the library:
std::env::set_var("FM_URL", "https://fm.example.com/fmi/data/vLatest");
Replace "https://fm.example.com/fmi/data/vLatest" with the actual URL of your FileMaker server.
In version 0.2.x, the library uses a new method to set the URL:
Filemaker::set_fm_url("https://fm.example.com/fmi/data/vLatest")?;
Retrieve specific records with pagination:
let records = filemaker.get_records(1, 10).await?;
println!("Fetched Records: {:?}", records);
Fetch all records at once:
let all_records = filemaker.get_all_records().await?;
println!("All Records: {:?}", all_records);
To add a single record to your FileMaker database:
use serde_json::Value;
use std::collections::HashMap;
let mut single_record_data = HashMap::new();
single_record_data.insert("field_name1".to_string(), Value::String("Value 1".to_string()));
single_record_data.insert("field_name2".to_string(), Value::String("Value 2".to_string()));
let result = filemaker.add_record(single_record_data).await?;
println!("Single record added: {:?}", result);
To add multiple records to your FileMaker database:
use serde_json::Value;
use std::collections::HashMap;
let records = vec![
{
let mut record = HashMap::new();
record.insert("field_name1".to_string(), Value::String("First Record - Value 1".to_string()));
record.insert("field_name2".to_string(), Value::String("First Record - Value 2".to_string()));
record
},
{
let mut record = HashMap::new();
record.insert("field_name1".to_string(), Value::String("Second Record - Value 1".to_string()));
record.insert("field_name2".to_string(), Value::String("Second Record - Value 2".to_string()));
record
},
];
for (i, record_data) in records.into_iter().enumerate() {
match filemaker.add_record(record_data).await {
Ok(result) => println!("Record {} added successfully: {:?}", i + 1, result),
Err(e) => eprintln!("Failed to add record {}: {}", i + 1, e),
}
}
Count the total number of records available in the table:
let total_records = filemaker.get_number_of_records().await?;
println!("Total Records: {}", total_records);
Perform a query with search parameters and sorting:
use std::collections::HashMap;
let mut query = HashMap::new();
query.insert("fieldName".to_string(), "example_value".to_string());
let sort_fields = vec!["fieldName".to_string()];
let ascending = true;
let search_results = filemaker.search::<serde_json::Value>(vec![query], sort_fields, ascending).await?;
println!("Search Results: {:?}", search_results);
Update a record by its ID:
use serde_json::Value;
let record_id = 123;
let mut field_data = HashMap::new();
field_data.insert("fieldName".to_string(), Value::String("new_value".to_string()));
let update_result = filemaker.update_record(record_id, field_data).await?;
println!("Update Result: {:?}", update_result);
Delete a record by its ID:
let record_id = 123;
filemaker.delete_record(record_id).await?;
println!("Record deleted successfully.");
Retrieve a list of layouts in the specified database:
let layouts = Filemaker::get_layouts("your_username", "your_password", "your_database").await?;
println!("Available Layouts: {:?}", layouts);
Retrieve the list of databases accessible with your credentials:
let databases = Filemaker::get_databases("your_username", "your_password").await?;
println!("Databases: {:?}", databases);
Delete all records from the current database and table:
filemaker.clear_database().await?;
println!("All records cleared successfully.");
This library comes with example implementations usable as references:
get_databasesfilemaker_layout_fetchermain_filemakerfilemaker_single_record_adderfilemaker_multiple_record_adderfilemaker_record_updaterfilemaker_record_deleterfilemaker_search_results_outputThe library uses the log crate for logging. To capture and display logs, set up a logging framework such as env_logger. Example:
use env_logger;
fn main() {
env_logger::init();
}
This library is licensed under the terms of the license detailed in the LICENSE file.
For more information, please refer to the repository documentation. Contributions are welcome!