I'm playing with a small web app in web.py, and url to return a JSON object I am establishing. What is the best way to change the SQL table using Ajithan?
Personally I like this kind of thing for some quick and dirty test codes I had to get it:
import from import sqlobject imported easily * # replace it with url for your actual database connection = connectionForURI ('sqlite: /: memory:') Sqlhub.processConnection = connection # This defines the columns for your database table. See SQLBuiz Docs how it converts it to # class attributes & lt; - & gt; The database column (usually the case of camel # case, usually) class song (SQL ads): name = stringcode () artist = stringcode () album = StringCol () # create duplicate data for demo - this is the real thing def MakeFakeDB (): Song.createTable () s1 = Song (name = "B Song", artist = "Artist1", album = "Album1") s2 = Song (name = "A Song", artist = "Artist2 ", Album =" album2 ") def main (): # this is a dynamic, not a list all_songs = Song.select (). OrderBy (Song.q.name) songs_as_dict = [] All_songs for the song: song_as_dict = {'name': song .name, 'artist': song.artist, 'album': song.album} songs_as_dict.append (song_as_dict ) Print simplejson.dumps (songs_as_dict) if __name__ == "__main__": MakeFakeDB () Main ()
Comments
Post a Comment