root/DB/TestModel.lua

Revision 945 (checked in by rsz, 2 years ago)

cleanup

Line 
1 package.path = package.path .. ";/Users/rszwarc/Developer/Lua/LU/?.lua"
2 package.cpath = package.cpath .. ";/Users/rszwarc/Developer/Lua/LU/Library/Modules/?.so"
3
4 local LUMap = require( "LUMap" )
5 local LUFile = require( "LUFile" )
6 local LUObjectWriter = require( "LUObjectWriter" )
7 local LUObjectReader = require( "LUObjectReader" )
8 local DBModel = require( "DBModel" )
9 local DBModelNaming = require( "DBModelNaming" )
10 -- local DBModelStatement = require( "DBModelStatement" )
11
12 print( DBModelNaming:dbName( "DBModelNaming" ) )
13 print( DBModelNaming:dbName( "cityId" ) )
14
15 local aRow = LUMap( { id = "JP", name = "Japan", capitalId = 12345 } )
16 -- local aRow = LUMap( { id = 12345, name = "Tokyo", countryId = "JP" } )
17
18 DBModel:load( function()
19         Is( Author )
20         Has( name )
21         HasMany( publishers )
22         HasMany( books )
23 end )
24        
25 DBModel:load( function()
26         Is( Book )
27         Has( title )
28         Has( price )
29         HasOne( publisher )
30         HasMany( authors )
31 end )
32        
33 DBModel:load( function()
34         Is( Publisher )
35         Has( name )
36         HasMany( authors )
37         HasMany( books )
38 end )
39
40 --[[
41 DBModel:load( function()
42         Is( Production )
43         HasMany( runs, ProductionVenue )
44         HasMany( venues )
45 end )
46
47 DBModel:load( function()
48         Is( Venue )
49         HasMany( runs, ProductionVenue )
50         HasMany( productions )
51 end )
52
53 DBModel:load( function()
54         Is( ProductionVenue )
55         HasOne( production )
56         HasOne( venue )
57 end )
58 ]]--
59
60 --[[
61 DBModel:load( function()
62         Is( DBSchema, information_schema.schemata )
63         Id( name, schema_name )
64         HasMany( tables, DBSchemaTable, Join( name, schemaName ) )
65 end )
66
67 DBModel:load( function()
68         Is( DBSchemaTable, information_schema.tables )
69         Id( schemaName, table_schema )
70         Id( name, table_name )
71         Has( type, table_type )
72         HasOne( schema, DBSchema, Join( schemaName, name ) )
73         HasMany( columns, DBSchemaColumn, Join( schemaName, schemaName ), Join( name, tableName ) )
74
75 end )
76
77 DBModel:load( function()
78         Is( DBSchemaColumn, information_schema.columns )
79         Id( schemaName, table_schema )
80         Id( tableName, table_name )
81         Id( name, column_name )
82         Has( type, data_type )
83         HasOne( table, DBSchemaTable, Join( schemaName, schemaName ), Join( tableName, name ) )
84 end )
85 ]]--
86
87 --[[
88 DBModel:load( function()
89         Is( Node )
90         HasOne( next, Node )
91         HasOne( previous, Node )
92         HasOne( parent, Node )
93         HasMany( children, Node, Join( id, parentId ) )
94 end )
95 ]]--
96
97 for _, anEntity in DBModel:entities():values():sort():iterator() do
98         print( anEntity:description() )
99                
100         for _, aRelation in anEntity:relations():values():sort():iterator() do
101                 print( "", aRelation:name(), aRelation:inverse(), aRelation:isOne(), aRelation:isMany(), aRelation:isToMany()  )
102                 print( "", "", aRelation:selectRow( aRow ) )
103         end
104 end
105
106
107 -- LUFile( "model.txt" ):setContent( LUObjectWriter:write( DBModel:entities() ) )
108 -- print( LUObjectReader:read( LUFile( "model.txt" ):content() ) )
109
Note: See TracBrowser for help on using the browser.