0.1.10 • Published 5 years ago
mongodb-schema-parser v0.1.10
mongodb-schema-parser
Infer a probabilistic schema for a MongoDB collection. This library is meant to be used in Rust or as Web Assembly module in JavaScript.
Usage: in Rust
use SchemaParser
pub fn main () {
let mut file = fs::read_to_string("examples/fanclub.json").unwrap();
let file: Vec<&str> = file.split("\n").collect();
let schema_parser = SchemaParser::new();
for json in file {
schema_parser.write(&json)?;
}
let result = schema_parser.read();
println!("{:?}", result);
}
Usage: in JavaScript
Make sure your environment is setup for Web Assembly usage.
import { SchemaParser } from "mongodb-schema-parser";
const schemaParser = new SchemaParser()
// get the json file
fetch('./fanclub.json')
.then(response => response.text())
.then(data => {
var json = data.split("\n")
for (var i = 0; i < json.length; i++) {
if (json[i] !== '') {
// feed the parser json line by line
schemaParser.write(json[i])
}
}
// get the result as a json string
var result = schemaParser.toJson()
console.log(result)
})
Installation
$ cargo add mongodb-schema-parser