diegogub / aranGO

Golang driver for ArangoDB
Apache License 2.0
125 stars 31 forks source link

Put the JSON2AQL filter feature in a separate package #19

Closed solher closed 8 years ago

solher commented 8 years ago

Hi, I'm currently writing my own lightweight ArangoDB driver. Just 50 lines to run raw AQL because I don't need all the ORM-like features. I love your JSON2AQL feature (as I wrote the same thing for SQL) and I'd like to use it in my package. Could you move the feature in a separate package (or more easily inside a subpackage) ? I will pull request to help you write tests if you want.

I will use it like that:

func AQLFilter(json string) string {
    return aranGO.FilterJSON(json).Generate()
}

Thanks for your work !

diegogub commented 8 years ago

That's a good Idea! I will do it :) I will keep you updated. I have 2.6 update pending, so I will release both changes. And probably 2.7 ;) You are welcome!

solher commented 8 years ago

Thanks a lot !

solher commented 8 years ago

Hum... I've been working all day on the best way of filtering ArangoDB results and I think I'm going to follow another idea than the one I chose at the beginning.

ArangoDB, unlike SQL databases, allows a lot of data formatting inside AQL queries. To the point that when you query:

FOR d
IN documents
RETURN {
    document: d,
    metaData: (
        FOR m
        IN metaData
        FILTER m.documentId == d._id
        RETURN m
    )
}

You don't really know what to put the filter on. I think I'm going to allow JSON filters like that (passed by query parameters from the API client):

{
    "limit": 2,
    "offset": 1,
    "where": {
        "and": [
            {"document._id": "document/4134113213"},
            {"metaData.title": { "neq": "foobar" } }
        ]
    }
}

To AQL:

LET result = (
    FOR d
    IN documents
    RETURN {
        document: d,
        metaData: (
            FOR m
            IN metaData
            FILTER m.documentId == d._id
            RETURN m
        )
    }
)

FOR var
IN result
LIMIT 1, 2
FILTER var.document._id == "document/4134113213" && var.metaData.title != "foobar"
RETURN var

It will not be the prettiest way all the time but I think it is the most powerful and versatile one for the client, and the easiest for the API developer.

diegogub commented 8 years ago

I see your point. I will review my code I see If I can improve JSON2AQL, yours is a good idea. Anyway, I moved orm and aql into 2 sub packages. Branch: json2aql. regards!

solher commented 8 years ago

I just released my driver on GitHub ! I reused the query generator I wrote for SQL, check it out: https://github.com/solher/arangolite Looks like you're not alone anymore using ArangoDB with Go haha.

Thanks a lot for your work anyway ;)

diegogub commented 8 years ago

:D great! :)

solher commented 8 years ago

Oh and just one thing. How do you feel about the ArangoDB transaction system ?

To me, the way they force you to write a Javascript function is just disgusting. You end up with JS code everywhere inside your Go code.

diegogub commented 8 years ago

Yes. same here. I guess we should build some kind of wrapper. But we need to include javascript in Golang driver :( . One solution I found quite interesting, is to send JSON to the server, with actions to do in a transaction and data, then build corresponding Fox app to do it server side.