PocketBaseCore 1.0.1

dotnet add package PocketBaseCore --version 1.0.1                
NuGet\Install-Package PocketBaseCore -Version 1.0.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="PocketBaseCore" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add PocketBaseCore --version 1.0.1                
#r "nuget: PocketBaseCore, 1.0.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install PocketBaseCore as a Cake Addin
#addin nuget:?package=PocketBaseCore&version=1.0.1

// Install PocketBaseCore as a Cake Tool
#tool nuget:?package=PocketBaseCore&version=1.0.1                

PocketBaseCore

A .NET Core and Standard 2.0 wrapper for the PocketBase API.

Installation

Install the package via NuGet:

dotnet add package PocketBaseCore

Usage

Authentication

Before making any requests, authenticate with the API:

var client = new PocketBaseClient("https://your-pocketbase-url");
var authResponse = await client.AuthenticateAsync("your-identity", "your-password");

// or you can pass a custom entity (inheriting from PocketBaseUser) if there are custom fields in the User table (ie: name, avatar, etc)
var authResponse = await client.AuthenticateAsync<MyPocketUser>("your-identity", "your-password");

Creating Records

To create a record using a custom POCO class:

var company = new Company
{
    Name = "Acme Inc",
    Website = "https://acme.com",
    Sector = "Technology"
};

company = await client.CreateRecordAsync<Company>("company", company);

If you prefer not to use a custom POCO class, you can use JsonNode instead:

var company = new JsonObject
{
    ["name"] = "Acme Inc",
    ["website"] = "https://acme.com",
    ["sector"] = "Technology"
};

company = await client.CreateRecordAsync<JsonNode>("company", company);

Updating a Record

To update a record:

var updateData = new Dictionary<string, object>
{
    { "name", "New Acme Inc" }
};

company = await client.UpdateRecordAsync<Company>("company", company.Id, updateData);

Alternatively, using JsonNode:

var updateData = new JsonObject
{
    ["name"] = "New Acme Inc"
};

company = await client.UpdateRecordAsync<JsonNode>("company", company["id"].ToString(), updateData);

Retrieving a Record

To retrieve a record:

var retrievedCompany = await client.GetRecordAsync<Company>("company", company.Id);

Or with JsonNode:

var retrievedCompany = await client.GetRecordAsync<JsonNode>("company", company["id"].ToString());

Working with Relationships

To create records with relationships:

// Create a company
var company = new Company
{
    Name = "Acme Inc",
    Website = "https://acme.com",
    Sector = "Technology"
};
company = await client.CreateRecordAsync<Company>("company", company);

// Create an employee
var employee = new Employee
{
    FullName = "John Doe",
    Email = "johndoe@acme.com",
    PhoneNumber = "1234567890",
    Company = company.Id
};

employee = await client.CreateRecordAsync<Employee>("employee", employee, expand: "company");

Or using JsonNode for both:

// Create a company
var company = new JsonObject
{
    ["name"] = "Acme Inc",
    ["website"] = "https://acme.com",
    ["sector"] = "Technology"
};
company = await client.CreateRecordAsync<JsonNode>("company", company);

// Create an employee
var employee = new JsonObject
{
    ["fullName"] = "John Doe",
    ["email"] = "johndoe@acme.com",
    ["phoneNumber"] = "1234567890",
    ["company"] = company["id"].ToString()
};

employee = await client.CreateRecordAsync<JsonNode>("employee", employee, expand: "company");

Filtering and Sorting

To filter and sort a collection:

var companiesSorted = await client.GetRecordsAsync<Company>("company", fields: "id,name,sector", sort: "-name");
var companiesFiltered = await client.GetRecordsAsync<Company>("company", filter: "(name = 'Company 5')");

Or using JsonNode:

var companiesSorted = await client.GetRecordsAsync<JsonNode>("company", fields: "id,name,sector", sort: "-name");
var companiesFiltered = await client.GetRecordsAsync<JsonNode>("company", filter: "(name = 'Company 5')");

Deleting Records

To delete records, use the following code:

// Delete a company
await client.DeleteRecordAsync("company", company.Id);

// Delete an employee
await client.DeleteRecordAsync("employee", employee.Id);

If using JsonNode:

// Delete a company
await client.DeleteRecordAsync("company", company["id"].ToString());

// Delete an employee
await client.DeleteRecordAsync("employee", employee["id"].ToString());

License

This project is licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.1 106 10/24/2024
1.0.0 107 10/19/2024

Initial release of PocketBaseCore.