Simple / Smart, a solution for the Pythonic database, can use syntax like Python +? (Key / Value Dict, Array, possibly Dict)

We are looking for solutions that push the envelope, and:

Avoid

  • Manually write SQL queries (Python may be larger than OO without passing DSL strings)
  • Using Non-Python Data Types for the Prospective Model Definition
  • Using a new class of types, rather than perfectly good native Python types

Boast of

  • Using Python Objects
  • Using Object Oriented and Key-Based Search and Creation
  • Fast proto-racing
  • No SQL table to create
  • Model / type inference or lack of model
  • Less lines and characters to enter

It is easy to output to JSON , possibly XML or even protocol buffers .

I am developing web applications, desktop computers and mobile devices, the better portability.

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 code above should work with very little change or thinking. Like the other import statement and maybe a little more, but Django and SQLAlchemy Models DO NOT CUT IT .

I'm looking for more interesting library suggestions than just "Try Shelve" or "use pickle"

I don't mind Python classes being used for models, but they should be really simple, unlike what you see with Django and the like.

+4
source share
5 answers

I really worked on something similar earlier today. There are no readme tests yet or enough, but ... http://github.com/mikeboers/LiteMap/blob/master/litemap.py

The LiteMap class behaves the same as the built-in dict, but it is stored in the SQLite database. You did not indicate which specific database you are interested in, but it can be almost trivially changed to either end.

It also does not track changes in mutable classes (for example, like adding to the list in your example), but the API is really simple.

+2
source

Access to the database does not improve than SQLAlchemy .

+1
source

Help explain what you won't find about Django models simply? This is how I will do what you have in 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 

I think it's very simple! In addition, the results are in a slightly cleaner naming scheme for IMO table / object names. The more complex part uses the Django DB module separately from the rest of Django, if that is what you need, but it can be done.

+1
source

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 back-end database servers + Google engine.

+1
source

The question looks strikingly similar to http://api.mongodb.org/python/1.9%2B/tutorial.html

So the answer is pymongo, what else;)

 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 have not tested the code, but not much different from this

BTW Redish is also interesting and interesting.

+1
source

Source: https://habr.com/ru/post/1311802/


All Articles