Friday, August 24, 2018

Is an ORM redundant with a NoSQL API?

with MongoDB (and I assume other NoSQL database APIs worth their salt) the ways of querying the database are much more simplistic than SQL. There is no tedious SQL queries to generate and such. For instance take this from mongodb-csharp:

using MongoDB.Driver; 
Mongo db = new Mongo(); 
db.Connect(); //Connect to localhost on the default port. 
Document query = new Document(); 
query["field1"] = 10; 
Document result = db["tests"]["reads"].FindOne(query); 
db.Disconnect();

How could an ORM even simplify that? Is an ORM or other "database abstraction device" required on top of a decent NoSQL API?

Solved

Well, yes, Object-Relational mappers are redundant with MongoDB because MongoDB isn't a relational database, it's a Document-Oriented database.

So instead of SQL, you write queries in JSON. Unless you really, really want to write raw JSON, as opposed to, say, Linq, then you're still going to want to use a mapper. And if you don't want to create coupling against MongoDB itself, then you don't want to pass actual Document objects around, you want to map them to real POCOs.

The mapping is much easier with a document-oriented DB like MongoDB, because you have nested documents instead of relations, but that doesn't mean it goes away completely. It just means you've substituted one type of "impedance mismatch" for a different, slightly-less-dramatic mismatch.


I think an "ORM" on MongoDb can be useful, not only for "serializing" and "deserializing" objects into the db (Norm seems to do a great job) but also for making it more easy to execute aggregation queries.

It is nice if an "ORM" can generate MapReduce jobs for grouping and detecting duplicates. Some people have written code to automatically convert an sql statement into a mapreduce job: http://rickosborne.org/blog/index.php/2010/02/19/yes-virginia-thats-automated-sql-to-mongodb-mapreduce/


Take a look on Kundera : https://github.com/impetus-opensource/Kundera, ORM over mongodb, cassandra, HBase.


Another solution is PlayOrm which can do joins as well when necessary with it's Scalable-SQL language(just adds a prefix to normal SQL basically to add partition info).


depends upon how mature is driver provided with the NoSQL database. This link discusses relevance of ORM tools for NoSQL database: http://xamry.wordpress.com/2012/08/10/sqlifying-nosql-are-orm-tools-relevant-to-nosql/


All you really need is a serializer/deserializer to make this work.

Norm has done a great job of doing just that. Makes it easier to take straight poco objects and just save them to mongo with a single line of code.

They call Norm an ORM, but its really just a poco to dictionary mongo wrapper.

An orm is just extra ceremony for these operations. If your data operations are abstracted into a repository, its going to be a non-issue either way, because converting to another backing store is an object per object, basis.


Monday, August 20, 2018

How to make datatable blank in Vb.net?

I have a data table which has few rows and columns. I need to delete the entire data along with column names also.

Eg :

                 Item | 2017 | 2018 | 2019 | 2020
                ----------------------------------
                 A      400    200   300     500
                 B      400    300   500     100
                 C      100    200   500     300
                 D      100    300   400     100

I need to delete all the data of the above data table along with the column names so that I can re-use the same data table for storing other values.

I tried datatable.clear() method it is clearing only the data, the column names remain intact and also I can't use dispose().

How can I do it.?

Solved

Short version here:

Dim dt As New DataTable

'...
'you do some operations
'...

dt = New DataTable 'renew the same instance

Alternatively, you can use:

dt = Nothing 'basically setting it to NULL

This should work:

datatable.Clear()             'clear records
datatable.Constraints.Clear() 'clear constraints (required before Columns.Clear(), if there is any constraint)
datatable.Columns.Clear()     'clear columns

Or this:

datatable.Reset()

But if you want to just create a new "blank" instance, or in other words, reinitialize it:

datatable = New Datatable

The solution that work for me is the following

datatable.Reset()

Sunday, August 19, 2018

How do I zip a file in Python without adding folders?

Currently I use the following code:

import zipfile

root_path = 'C:/data/'

def zipping_sql_database():
    zf = zipfile.ZipFile(root_path + 'file.zip', mode='w')
    try:
        zf.write(root_path + "file.db")
    finally:
        zf.close()

At the moment it creates a zip-file but the zip files contains the whole folder named 'data' that then contains the 'file.db'. How can I create a zip-file only contains 'file.db' and not the file in a folder?

Solved

I found that I get the right behavior via:

import zipfile

root_path = 'C:/data/'

def zipping_sql_database():
    zf = zipfile.ZipFile(root_path + 'file.zip', mode='w')
    try:
        zf.write(root_path + "file.db", "file.db")
    finally:
        zf.close()

Saturday, August 18, 2018

how to watermark mp4 video with ffmpeg php

I need to watermark a mp4 video , Currently i am using this code, but it is not working , please solve this


Solved

You need to put the filter code within double quotes. If you could share more about the error you're facing, I'll be able to help you better.