This is an example Haxe project scaffolded by Visual Studio Code.
Without further changes the structure is following:
src/Main.hx: Entry point Haxe source filebuild.hxml: Haxe command line file used to build the projectREADME.md: This file
Convert Hscript expressions into MongoDB queries (using aggregation pipeline operators).
Also supports the JS sequelize library.
Run:
haxe mongo.hxml
Then:
const {MongoEngine} = require('./bin/js/mongo-engine').bp.hquery;
const engine = new MongoEngine();
const parsed = engine.parse("x == 5 && y <= 10");
if(parsed.ok) {
console.log(parsed.result);
} else {
console.error(parsed.error);
}Run:
haxe sequelize.hxml
Then:
const sequelize = /* get a sequelize instance */
const {SequelizeEngine} = require('./bin/js/sequelize-engine').bp.hquery;
const engine = new SequelizeEngine(sequelize);
const parsed = engine.parse("foo.like('%bar%') && baz.notLike('%qux%')");
if(parsed.ok) {
console.log(parsed.result);
} else {
console.error(parsed.error);
}foo == barbecomes:
{
"$eq": [
"$foo",
"$bar"
]
}foo == "baz"becomes:
{
"$eq": [
"$foo",
"baz"
]
}val.isIn([1,2,3])becomes:
{
"$in": [
"$val",
[
1,
2,
3
]
]
}
(x < 10 && y > 10) || (x > -10 && y < -10)becomes:
{
"$or": [
{
"$and": [
{
"$lt": [
"$x",
10
]
},
{
"$gt": [
"$y",
10
]
}
]
},
{
"$and": [
{
"$gt": [
"$x",
-10
]
},
{
"$lt": [
"$y",
-10
]
}
]
}
]
}