https://github.com/miniql/miniql-json
A MiniQL query resolver that loads data from JSON files.
https://github.com/miniql/miniql-json
data json query query-language
Last synced: 23 days ago
JSON representation
A MiniQL query resolver that loads data from JSON files.
- Host: GitHub
- URL: https://github.com/miniql/miniql-json
- Owner: miniql
- License: mit
- Created: 2020-07-27T04:45:30.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-05-30T09:19:57.000Z (over 3 years ago)
- Last Synced: 2025-10-10T20:15:03.568Z (2 months ago)
- Topics: data, json, query, query-language
- Language: TypeScript
- Homepage:
- Size: 73.2 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# @miniql/csv
A [MiniQL](https://github.com/miniql/miniql) query resolver that loads data from CSV files.
Any problems? Please log an issue on this repo.
Love this? Please [star the repo](https://github.com/miniql/miniql) and [support my work](https://www.codecapers.com.au/about#support-my-work)
## Example
Find a complete and working Node.js example of using MiniQL with a CSV file dataset here:
https://github.com/miniql/miniql-csv-example
## Using it
Install the modules in your Node.js project:
```bash
npm install --save miniql
npm install --save @miniql/csv
```
Import the modules (JavaScript):
```javascript
const { miniql } = require("miniql");
const { createQueryResolver } = require("@miniql/csv");
```
Import the modules (TypeScript):
```typescript
import { miniql } from "miniql";
import { createQueryResolver } from "@miniql/csv";
```
Configure and create the CSV files query resolver:
```javascript
//
// Configures CSV files to be loaded and how they relate to each other.
//
const csvFilesConfig = {
species: {
primaryKey: "name",
csvFilePath: "./data/species.csv",
nested: {
homeworld: {
parentKey: "homeworld",
from: "planet",
},
},
},
planet: {
primaryKey: "name",
csvFilePath: "./data/planets.csv",
nested: {
species: {
foreignKey: "homeworld",
},
},
},
};
//
// Loads CSV files and creates a MiniQL query resolver.
//
const queryResolver = await createQueryResolver(csvFilesConfig);
```
Now you can make queries against the dataset, for example:
```javascript
const query = {
get: {
species: { // Query for "species" entity.
// No arguments gets all entities.
resolve: {
homeworld: { // Resolves the homeworld of each species as a nested lookup.
},
}
},
},
};
// Invokes MiniQL.
const result = await miniql(query, queryResolver, {});
// Displays the query result.
console.log(JSON.stringify(result, null, 4));
```
Please see [MiniQL](https://github.com/miniql/miniql) for more information on how to make queries.
Don't forget to [star the repo](https://github.com/miniql/miniql) and [follow the developer on Twitter](https://twitter.com/codecapers).