Is there any API that makes data store/retrieve easy?
I really hate when I want to store/fetch something from the database, I have to issue a SQL command and wait for the response, and before that I need to create the table and think carefully about the data types. The code is replicates all over the source, every time I need to talk to SQL I am very tired.
I am thinking about is there any easy way of this? Like when I want to insert a line to a table:
Table1 table;
table.insert("bbb", "ccc", "ddd");
table.insert("colA":"bbb", "colB":"ccc");
Also I don't need to create the table in SQL manually, just declare in the high level language:
Table1 {
colA
colB
}
To find the specific element:
table.find({"colA" = "bbb"});
Or, even better, if the data is stored in XML style, we don't need to 开发者_如何学JAVAmake every row the same columns, it's free style.
You know what I mean.
Is there existing ones with good high level language support? Python?
What you may be looking for is an ORM (Object-Relational Mapping) library, which abstracts you from the database so that you don't have to write SQL in many cases. In regard to your question about Python--yes, dynamic languages like Python and Ruby are good for this sort of thing. But ORM libraries are available in just about any language. The second possibility is NoSQL.
ORM
I'll give you a couple quick examples in Ruby on Rails, using its built-in ORM, ActiveRecord. Let's say you have a 'users' table with 'name' and 'age' columns.
Inserting into the table:
user = User.new
user.name = "Bin Chen"
user.age = 30
user.save
Finding records:
User.where(:name => "Bin Chen")
User.where(:age => 20..40)
ActiveRecord even creates dynamic methods based on your columns:
User.find_by_age(30)
User.find_or_create_by_name("Bob", :age => 20)
Specifying a table is indeed simple and declarative. There are quite a few tutorials and screencasts available, if you're interested.
NoSQL
If you don't need a relational database, then NoSQL may fit the bill. These tend to be specialized for certain types of data, and usually optimized for performance. Examples are MongoDB, CouchDB for general purpose document databases, Redis for key/value store, eXist for XML storage. Many options are listed at http://nosql-database.org/. Most of these have language bindings for dynamic languages such as Python.
Assuming you really aren't looking to use a relational database (which is the right tool for the job in 90%+ of cases), take a look at document or "NoSQL" databases. Some examples are MongoDB and CouchDB.
I think what you are talking about is some kind of Object Relational Mapping (ORM) tool, something like Hibernate, or Linq-to-Entities, where the code to issue the SQL is generated for you, and you can then concentrate on your business logic.
Should point out that I don't know python particularly, but I'm sure there is a tool like this in existence.
In fact, quick google brings up this:
What are some good Python ORM solutions?
You can use Oracle Berkeley DB XML. It's FOSS, it has a Python API, you can have schemaless containers and store any document you want in them.
精彩评论