haxiomic / dts2hx

Converts TypeScript definition files (d.ts) to haxe externs (.hx) via the TypeScript compiler API
MIT License
136 stars 9 forks source link

how to support obj={"site": /A/}? #53

Closed sonygod closed 4 years ago

sonygod commented 4 years ago

dts2hx mongodb

– SQL:
SELECT * FROM UserInfo WHERE userName LIKE "%A%"

– MongoDB:
db.UserInfo.find({userName: /A/})

but haxe current not support

var obj={ "site" : /A/};

any suggestion? thanks.
    package;

    import mongodb.MongoClient;
    import Mongodb;

    using tink.CoreApi;

    @await
    class Main {
        public static function main() {
            testMongodb();
        }

        @async
        public static function testMongodb() {
            var url = "mongodb://127.0.0.1:27017";

            var connect:MongoClient = @await Mongodb.connect(url, {useUnifiedTopology: true}).ofJsPromise();

            var test = connect.db("testdb").collection('test1');

            var effect = @await test.insertOne({"site": "runoob.com" + Random.int(1, 1000000)}).ofJsPromise();
            @await test.insertOne({"site": "runoob.com"}).ofJsPromise();

            @await test.update({"site": "runoob.com"}, {$set:{"site":"example.com"}}).ofJsPromise();

            @await test.deleteMany({"site": /runoob/}).ofJsPromise(); // here is not support.
            var arr = @await test.find().toArray().ofJsPromise();

            trace(arr);
        }
    }
sonygod commented 4 years ago

Syntax.code("/example/")