Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: allow serializing T to create/update/replace record #92

Open
jomhyre opened this issue Mar 3, 2025 · 0 comments
Open

Comments

@jomhyre
Copy link

jomhyre commented Mar 3, 2025

It would be useful to have overloads of Create/Update/Replace which can serialize a given object, similarly to how we have RetrieveRecord which deserializes the response to T. It would help to avoid duplication and mistakes which seem to come with using Fields

a brief example of how I'd probably use it:

public class MyAirtableRecord
{
    [JsonPropertyName("fldrabcdefg")]
    public string? Description { get; set; }

    [JsonPropertyName("fldrhijklmn")]
    public AirtableAttachment? File { get; set; }
    
    [JsonPropertyName("fldr1234567")]
    public int? Rating { get; set; }
}

public class CustomAirtableClient
{
    private readonly AirtableBase _base;
    private readonly string _tableId;

    // some initialization...

    public async Task<MyAirtableRecord> Get(string recordId)
    {
        var record = await this._base.RetrieveRecord<MyAirtableRecord>(_tableId, recordId, returnFieldsByFieldId: true);
        return record.Record;
    }

    public async Task<string> Create(MyAirtableRecord data)
    {
        var record = await this._base.CreateRecord(_tableId, data);
        return record.Id;
    }

    public async Task Update(string recordId, MyAirtableRecord data)
    {
        await this._base.UpdateRecord(_tableId, recordId, data);
    }
}

At least one issue comes to mind that would need to be dealt with:

When updating, how do we handle null values? You probably want to ignore them in most cases, but you may sometimes want to actually clear a given column in airtable - in that case it might be easiest to say that you need to fallback to using a Fields.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant