viewschema.py :  » Database » PyTable » pytable-0.8.20a » pytable » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Database » PyTable 
PyTable » pytable 0.8.20a » pytable » viewschema.py
"""(incomplete) Schemas describing query/view structures"""
from basicproperty import propertied,common,basic
from basictypes import list_types,callable
from pytable import dbschema

class ViewFieldSchema( dbschema.FieldSchema ):
  """A view-field description, adds source table and field props

  Basically, a default ViewField is going to use
  these extra properties to forward all actions to
  the source-table's field for standard editing
  actions.
  """
  sourceTable = basic.BasicProperty(
    'sourceTable', """The source-table schema for this field (may be null)""",
    baseType = dbschema.TableSchema,
  )
  sourceField = basic.BasicProperty(
    'sourceField', """The source-field schema for this field (may be null)""",
    baseType = dbschema.FieldSchema,
  )

ViewFieldSchemas = list_types.listof(
  ViewFieldSchema,
  name = "ViewFieldSchemas",
  dataType = "list.ViewFieldSchemas",
)

class JoinTable( dbschema.Schema ):
  """A Join of a table, basically just a name:table item"""
  name = common.StringProperty(
    'name', """Name of the table (required)""",
    defaultFunction = lambda prop, client: client.table.name,
  )
  table = basic.BasicProperty(
    'table', """Table object which participates in the schema""",
    baseType = dbschema.TableSchema,
  )
  def check( cls, value ):
    """Check that value is a proper instance of this class"""
    if isinstance( value, cls ):
      if hasattr( value, table ):
        return 1
    return 0
  check = classmethod( check )
  def coerce( cls, value ):
    """Coerce a value to an instance of this class"""
    if cls.check( value ):
      return value
    if isinstance( value, dbschema.TableSchema ):
      return cls( table = value )
    else:
      raise TypeError("""%r couldn't be converted to a %s"""%(value, cls.__name__))
  coerce = classmethod( coerce )

JoinTables = list_types.listof(
  JoinTable,
  name = "JoinTables",
  dataType = "list.JoinTables",
)

class ViewSchema( dbschema.BaseTableSchema ):
  """A query-view table-structure/schema

  This is the structure/schema for a query,
  and as such it may involve multiple tables,
  may include joins, indices and the like.

  At it's most basic, a view schema can
  just be:
  
    select * from tableName;

  but it can be ridiculously more complex,
  with huge numbers of sub-elements interacting
  to produce a real-world query-set.
  """
  tables = common.ListProperty(
    'tables', """List of JoinTable objects which participate in the schema""",
    baseType = JoinTables,
  )
  fields = common.ListProperty(
    'fields', """FieldSchema objects for the table""",
    baseType = ViewFieldSchemas,
  )

ViewSchemas = list_types.listof(
  ViewSchema,
  name = "ViewSchemas",
  dataType = "list.ViewSchemas",
)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.