package.path = package.path .. ";/Users/rszwarc/Developer/Lua/LU/?.lua" package.cpath = package.cpath .. ";/Users/rszwarc/Developer/Lua/LU/Library/Modules/?.so" local LUMap = require( "LUMap" ) local LUFile = require( "LUFile" ) local LUObjectWriter = require( "LUObjectWriter" ) local LUObjectReader = require( "LUObjectReader" ) local DBModel = require( "DBModel" ) local DBModelNaming = require( "DBModelNaming" ) -- local DBModelStatement = require( "DBModelStatement" ) print( DBModelNaming:dbName( "DBModelNaming" ) ) print( DBModelNaming:dbName( "cityId" ) ) local aRow = LUMap( { id = "JP", name = "Japan", capitalId = 12345 } ) -- local aRow = LUMap( { id = 12345, name = "Tokyo", countryId = "JP" } ) DBModel:load( function() Is( Author ) Has( name ) HasMany( publishers ) HasMany( books ) end ) DBModel:load( function() Is( Book ) Has( title ) Has( price ) HasOne( publisher ) HasMany( authors ) end ) DBModel:load( function() Is( Publisher ) Has( name ) HasMany( authors ) HasMany( books ) end ) --[[ DBModel:load( function() Is( Production ) HasMany( runs, ProductionVenue ) HasMany( venues ) end ) DBModel:load( function() Is( Venue ) HasMany( runs, ProductionVenue ) HasMany( productions ) end ) DBModel:load( function() Is( ProductionVenue ) HasOne( production ) HasOne( venue ) end ) ]]-- --[[ DBModel:load( function() Is( DBSchema, information_schema.schemata ) Id( name, schema_name ) HasMany( tables, DBSchemaTable, Join( name, schemaName ) ) end ) DBModel:load( function() Is( DBSchemaTable, information_schema.tables ) Id( schemaName, table_schema ) Id( name, table_name ) Has( type, table_type ) HasOne( schema, DBSchema, Join( schemaName, name ) ) HasMany( columns, DBSchemaColumn, Join( schemaName, schemaName ), Join( name, tableName ) ) end ) DBModel:load( function() Is( DBSchemaColumn, information_schema.columns ) Id( schemaName, table_schema ) Id( tableName, table_name ) Id( name, column_name ) Has( type, data_type ) HasOne( table, DBSchemaTable, Join( schemaName, schemaName ), Join( tableName, name ) ) end ) ]]-- --[[ DBModel:load( function() Is( Node ) HasOne( next, Node ) HasOne( previous, Node ) HasOne( parent, Node ) HasMany( children, Node, Join( id, parentId ) ) end ) ]]-- for _, anEntity in DBModel:entities():values():sort():iterator() do print( anEntity:description() ) for _, aRelation in anEntity:relations():values():sort():iterator() do print( "", aRelation:name(), aRelation:inverse(), aRelation:isOne(), aRelation:isMany(), aRelation:isToMany() ) print( "", "", aRelation:selectRow( aRow ) ) end end -- LUFile( "model.txt" ):setContent( LUObjectWriter:write( DBModel:entities() ) ) -- print( LUObjectReader:read( LUFile( "model.txt" ):content() ) )