Thanks Torsten,

The guide worked right out of the box.

Many thanks for your help.

Craig

-----Original Message-----
From: Torsten Bergmann [mailto:asta...@gmx.de] 
Sent: 20 January 2015 11:42 AM
To: cr...@hivemind.net; Any question about pharo is welcome
Subject: Glorp on Pharo 4

Hi Craig,

see below a quick guide. Tell me when it works.
Someone should do a video from that...
 
Thanks
Torsten

------------------------------------------------------------------------------------------------------------------------------------------------
For Windows:
============
- go to http://www.sqlite.org/download.html and retrieve 
sqlite-dll-win32-x86-3080800.zip
- copy the included sqlite3.dll to the folder where your virtual machine 
(Pharo.exe) resides so it can be found by the NativeBoost wrapper later
  (as an alternative you can have in any folder that is accessible via PATH 
environment variable)

- open a fresh Pharo4.0 image (here I use latest update: #40451 image)
- load from ConfigurationBrowser: "Glorp"
- load from ConfigurationBrowser: "NBSQLite3"
- then open Monticello browser and select the repo for NBSQLite3, open it and
  load additionally "NBSQLite3-Glorp-TorstenBergmann.3"
- create a package "Killerapp-Core" using Nautilus system browser
- create a tag "Model" in this new package using Nautilus system browser
- create a class 
     
          Object subclass: #KillerAppUser
             instanceVariableNames: 'id username'
             classVariableNames: ''
             category: 'Killerapp-Core-Model'
                 
- click on the class in Nautilus browser and select "Refactoring" -> "Class 
Refactoring"
  and "Generate Accessors" to create accessor methods for the instance variables

- create a package "Killerapp-Persistence" using Nautilus system browser
- create a tag "Mappings" in this new package using Nautilus system browser

      DescriptorSystem subclass: #KillerAppDatabaseDescriptor
               instanceVariableNames: ''
               classVariableNames: ''
               category: 'Killerapp-Persistence-Mappings'

- implement an instance side method in method category 'accessing'

        allTableNames
                 ^ #('KILLERAPP_USER')          
                   
- create an instance side method in category 'mapping-classes'

       constructAllClasses
              ^ super constructAllClasses
                      add: KillerAppUser;
                      yourself
                          
                          
- implement an instance side method in method category 'mapping - classes'

        classModelForKillerAppUser: aClassModel
                        #(#id #username) do: [ :each |
                                aClassModel newAttributeNamed: each ]   
                          
- create an instance side method in method category 'mapping - descriptors'

       descriptorForKillerAppUser: aDescriptor

          | table |
              table := self tableNamed: 'KILLERAPP_USER'.
                  aDescriptor table: table.
                  #(id username) do: [ :each |
                                (aDescriptor newMapping: DirectMapping) 
                                        from: each to: (table fieldNamed: each) 
]
                                        
                                        
- implement an instance side method in method category 'mapping - tables'
        
        tableForKILLERAPP_USER: aTable
                "Define the table KILLERAPP_USER"
                (aTable createFieldNamed: 'ID' type: platform sequence) 
                        isUnique: true;         
                        bePrimaryKey.   
                (aTable createFieldNamed: 'USERNAME' type: (platform varchar: 
20))
                        isUnique: true;
                        beNullable: false.                      
                                        
By having the descriptions set up you can now play with Glorp:

   |login accessor session|
   login := Login new.
   login host: ''.
   login databaseName: 'C:\db\killerapp.db'.
   login database: SQLite3Platform new.
   accessor := NBSQLite3DatabaseAccessor forLogin: login.
   accessor loginIfError: [ self error: 'unable to connect' ].
   session := GlorpSession new.
   session system: (KillerAppDatabaseDescriptor forPlatform: login database).
   session accessor: accessor.

   "Create all tables (only to be done once)"
   session createTables.

   "Create a new user"
   session inUnitOfWorkDo: [ 
      user := (KillerAppUser new)
      username: 'admin'.
      session register: user ].
        
Then you can use a tool like "SQLiteStudio" to open the database and check what 
is in the tables...


                                                


Reply via email to