xentixar/mantrajna

V0.1 2024-01-19 03:02 UTC

This package is auto-updated.

Last update: 2024-12-19 10:02:50 UTC


README

Mantrajna is a PHP library designed to provide a flexible and powerful way to manipulate and query tabular data from various sources, such as CSV, JSON, and XML files. It allows users to perform operations like filtering, sorting, formatting, and updating data seamlessly.

Table of Contents

Installation

To use Mantrajna in your project, you can install it using Composer:

composer require xentixar/mantrajna

Getting Started

Here's a basic example of using Mantrajna to read a CSV file and perform some operations:

<?php

use Xentixar\Mantrajna\Unicorn;

// Create an instance of Mantrajna Unicorn
$mantrajna = new Unicorn();

// Read data from a CSV file
$mantrajna->readCsv('example.csv');

// Filter data where the 'age' column is greater than 25
$mantrajna->where(['age', '>', 25]);

// Sort the data based on the 'name' column in descending order
$mantrajna->sort('name', 'DESC');

// Execute all the instruction
// Before using print or get you have to call run function to save all the changes.
$mantrajna->run();

// Print the resulting data
$mantrajna->print();

Supported Operations

Read Data

CSV

$mantrajna->readCsv('example.csv', ',');

JSON

$mantrajna->readJson('example.json');

XML

$mantrajna->readXml('example.xml');

Filtering and Sorting

Filtering

$mantrajna->where(['age', '>', 25]);

Sorting

$mantrajna->sort('name', 'DESC');

Formatting

Set Column Info

$mantrajna->setColumnInfo('birthdate:datetime:Y-m-d', 'score:double');

Format

$mantrajna->format('birthdate:Y-m-d');

Updating Data

Update

$mantrajna->update(['age', 'score'], [30, 95.5]);

Output Operations

Select Columns

$mantrajna->selectColumns('name', 'age');

Print Data

$mantrajna->print();

Output to JSON

$mantrajna->dumpJson('output.json');

Output to XML

$mantrajna->dumpXml('output.xml');

Output to CSV

$mantrajna->dumpCsv('output.csv', ',');

Examples

For more examples and use cases, refer to the examples directory in the Mantrajna GitHub repository.

Contributing

Contributions are welcome! If you find any issues or have suggestions, please open an issue or submit a pull request.

License

Mantrajna is open-source software licensed under the MIT license. Feel free to use and modify it as per your project requirements.