Looking for solutions that push the envelope and:
寻找解决方案,以及:
Avoid
- Manually writing SQL queries(Python can be more OO not passing DSL strings)
- Using non-Python datatypes for a supposedly required model definition
- Using a new class of types rather than perfectly good native Python types
手动编写SQL查询(Python可能更多OO不通过DSL字符串)
将非Python数据类型用于所需的模型定义
使用新类型而不是完美的原生Python类型
Boast
- Using Python objects
- Using Object Oriented and key based retrieval and creation
- Quick protoyping
- No SQL table to make
- Model /Type inference or no model
- Less lines and characters to type
使用Python对象
使用面向对象和基于密钥的检索和创建
没有SQL表
模型/类型推断或没有模型
输入更少的行和字符
Easily output to and from JSON, maybe XML or even Protocol Buffers.
轻松输出和输出JSON,可能是XML甚至是协议缓冲区。
I do web, desktop and mobile software development so the more portable the better.
我做网络,桌面和移动软件开发,因此越便携越好。
python
>> from someAmazingDB import *
>> db.taskList = []
>> db['taskList'].append({title:'Beat old sql interfaces','done':False})
>> db.taskList.append({title:'Illustrate different syntax modes','done':True})
#at this point it should autosave
#we should be able to reload the console and access like:
python
>> from someAmazingDB import *
>> print 'Done tasks'
>> for task in db.taskList:
>> if task.done:
>> print task
'Illustrate different syntax modes'
Here is the challenge: The above code should work with very little modification or thinking required. Like a different import statement and maybe a little more but Django Models and SQLAlchemy DO NOT CUT IT.
这是一个挑战:上面的代码应该只需要很少的修改或思考。就像一个不同的导入语句,也许更多,但Django模型和SQLAlchemy不要削减它。
I'm looking for more interesting library suggestions than just "Try Shelve" or "use pickle"
我正在寻找更多有趣的图书馆建议而不仅仅是“尝试搁置”或“使用泡菜”
I'm not opposed to Python classes being used for models but they should be really straight forward, unlike the stuff you see with Django and similar.
我并不反对用于模型的Python类,但它们应该非常直接,不像你用Django和类似的东西。
5 个解决方案
#1
2
I've was actually working on something like this earlier today. There is no readme or sufficient tests yet, but... http://github.com/mikeboers/LiteMap/blob/master/litemap.py
我今天早些时候正在做类似的事情。目前还没有自述或足够的测试,但是...... http://github.com/mikeboers/LiteMap/blob/master/litemap.py
The LiteMap
class behaves much like the builtin dict, but it persists into a SQLite database. You did not indicate what particular database you were interested in, but this could be almost trivially modified to any back end.
LiteMap类的行为与内置字典非常相似,但它仍然存在于SQLite数据库中。您没有指出您感兴趣的特定数据库,但这几乎可以简单地修改为任何后端。
It also does not track changes to mutable classes (e.g. like appending to the list in your example), but the API is really simple.
它也不跟踪可变类的更改(例如,在示例中附加到列表中),但API非常简单。
#3
1
Care to explain what about Django's models you don't find straightforward? Here's how I'd do what you have in Django:
注意解释Django的模型你觉得哪些不直接?这就是我在Django中做的事情:
from django.db import models
class Task(models.Model):
title = models.CharField(max_length=...)
is_done = models.BooleanField()
def __unicode__(self):
return self.title
----
from mysite.tasks.models import Task
t = Task(title='Beat old sql interfaces', is_done=True)
t.save()
----
from mysite.tasks.models import Task
print 'Done tasks'
for task in Task.objects.filter(is_done=True):
print task
Seems pretty straightforward to me! Also, results in a slightly cleaner table/object naming scheme IMO. The trickier part is using Django's DB module separate from the rest of Django, if that's what you're after, but it can be done.
对我来说似乎很简单!此外,导致稍微更清洁的表/对象命名方案IMO。更棘手的部分是使用Django的DB模块与Django的其余部分分开,如果这就是你所追求的,但它可以完成。
#4
1
Using web2py:
>>> from gluon.sql import DAL, Field
>>> db=DAL('sqlite://stoarge.db')
>>> db.define_table('taskList',Field('title'),Field('done','boolean')) # creates the table
>>> db['taskList'].insert(title='Beat old sql interfaces',done=False)
>>> db.taskList.insert(title='Beat old sql interfaces',done=False)
>> for task in db(db.taskList.done==True).select():
>> print task.title
Supports 10 different database back-ends + google app engine.
支持10种不同的数据库后端+谷歌应用引擎。
#5
1
Question looks strikingly similar to http://api.mongodb.org/python/1.9%2B/tutorial.html
问题看起来与http://api.mongodb.org/python/1.9%2B/tutorial.html非常相似
So answer is pymongo, what else ;)
所以答案是pymongo,还有什么;)
from pymongo import Connection
connection = Connection()
connection = Connection('localhost', 27017)
tasklist = db['test-tasklist']
tasklist.append({title:'Beat old sql interfaces','done':False})
db.tasklist.append({title:'Illustrate different syntax modes','done':True})
for task in db.tasklist.find({done:True}):
print task.title
I haven't tested the code but wont be very different than this
我没有测试过代码,但不会与此有很大的不同
BTW Redish is also interesting and fun.
BTW Redish也很有趣也很有趣。
#1
2
I've was actually working on something like this earlier today. There is no readme or sufficient tests yet, but... http://github.com/mikeboers/LiteMap/blob/master/litemap.py
我今天早些时候正在做类似的事情。目前还没有自述或足够的测试,但是...... http://github.com/mikeboers/LiteMap/blob/master/litemap.py
The LiteMap
class behaves much like the builtin dict, but it persists into a SQLite database. You did not indicate what particular database you were interested in, but this could be almost trivially modified to any back end.
LiteMap类的行为与内置字典非常相似,但它仍然存在于SQLite数据库中。您没有指出您感兴趣的特定数据库,但这几乎可以简单地修改为任何后端。
It also does not track changes to mutable classes (e.g. like appending to the list in your example), but the API is really simple.
它也不跟踪可变类的更改(例如,在示例中附加到列表中),但API非常简单。
#2
#3
1
Care to explain what about Django's models you don't find straightforward? Here's how I'd do what you have in Django:
注意解释Django的模型你觉得哪些不直接?这就是我在Django中做的事情:
from django.db import models
class Task(models.Model):
title = models.CharField(max_length=...)
is_done = models.BooleanField()
def __unicode__(self):
return self.title
----
from mysite.tasks.models import Task
t = Task(title='Beat old sql interfaces', is_done=True)
t.save()
----
from mysite.tasks.models import Task
print 'Done tasks'
for task in Task.objects.filter(is_done=True):
print task
Seems pretty straightforward to me! Also, results in a slightly cleaner table/object naming scheme IMO. The trickier part is using Django's DB module separate from the rest of Django, if that's what you're after, but it can be done.
对我来说似乎很简单!此外,导致稍微更清洁的表/对象命名方案IMO。更棘手的部分是使用Django的DB模块与Django的其余部分分开,如果这就是你所追求的,但它可以完成。
#4
1
Using web2py:
>>> from gluon.sql import DAL, Field
>>> db=DAL('sqlite://stoarge.db')
>>> db.define_table('taskList',Field('title'),Field('done','boolean')) # creates the table
>>> db['taskList'].insert(title='Beat old sql interfaces',done=False)
>>> db.taskList.insert(title='Beat old sql interfaces',done=False)
>> for task in db(db.taskList.done==True).select():
>> print task.title
Supports 10 different database back-ends + google app engine.
支持10种不同的数据库后端+谷歌应用引擎。
#5
1
Question looks strikingly similar to http://api.mongodb.org/python/1.9%2B/tutorial.html
问题看起来与http://api.mongodb.org/python/1.9%2B/tutorial.html非常相似
So answer is pymongo, what else ;)
所以答案是pymongo,还有什么;)
from pymongo import Connection
connection = Connection()
connection = Connection('localhost', 27017)
tasklist = db['test-tasklist']
tasklist.append({title:'Beat old sql interfaces','done':False})
db.tasklist.append({title:'Illustrate different syntax modes','done':True})
for task in db.tasklist.find({done:True}):
print task.title
I haven't tested the code but wont be very different than this
我没有测试过代码,但不会与此有很大的不同
BTW Redish is also interesting and fun.
BTW Redish也很有趣也很有趣。