A library for searching JSONB data in PostgreSQL.
$ dotnet add package SearchLibSearchLib is a C# library designed to search JSONB data stored in PostgreSQL tables. It allows users to perform dynamic SQL queries on specific JSON keys and values, supporting various data types such as numerical, string, boolean, and arrays. It also enables querying with multiple conditions, making it a flexible solution for working with JSONB data in PostgreSQL.
Add the SearchLib class to your project and ensure you have the following dependencies:
dotnet add package Npgsql
## Usage
### 1. Initialize the Library
First, initialize the `SearchLib` class by passing your PostgreSQL connection string:
```csharp
string connectionString = "Host=my_host;Port=5432;Username=my_user;Password=my_pw;Database=my_db";
var searchLib = new SearchLib(connectionString);
### 2. Searching Multiple JSON Keys
To search for multiple conditions on JSON keys, use the `SearchMultipleJsonKeys` method. Pass the table name, column name, and a dynamic array of conditions.
Each condition must contain the `JsonKey`, `ExpectedValue`, and `Operand`.
#### Example:
```csharp
dynamic conditions = new[] {
new { JsonKey = "fps", ExpectedValue = 30, Operand = ">" },
new { JsonKey = "resolution", ExpectedValue = "1080p", Operand = "=" }
};
var multiResults = searchLib.SearchMultipleJsonKeys(
"VideoSourceConfigs", // Table name
"Basic_Params", // Column name storing JSONB data
conditions
);