Skip to content

rvillemeur/glorpbook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Experiment based on : Pharo smalltalk glorp book

Metacello new
	baseline: 'GlorpBook';
	repository: 'github://rvillemeur/glorpbook/repository';
	load

short glop cheat sheet

Domain model Class: #Person, stored in table PERSON in database.

  1. DescriptorSystem subclass
    1. DescriptorSystem subclass: #GlorpBookDescriptorSystem
    2. classModelForYourClass (ex: classModelForPerson) Messages use to list attributes of Model
    3. tableForYOURTABLE (ex: tableForPERSON) Message describing fields in the table
    4. descriptorForYourClass (ex: descriptorForPerson) Link between attributes ofs classModelForXXX and fields of tableForXXX
  2. System, session et database accessor.
    1. Create login message to retreive the login
    2. Use the Login you've just created to retreive the accessor
    3. You can then retrive the session session using the message sessionForLogin, which will link login, accessor and session.

Once connected to the database, you have to run in pharo workspace "session createTables" to create the table in your new database

Record you work in your session, use the message >> inUnitOfWorkDo: [ … ]

SQL Glorp
Select * from TABLE Session read: DomainClass
Select * from TABLE where attributes = 'value' Session read: DomainClass where: [:each | each attribute = 'value']
Select * from TABLE where attributes like 'value%' Session read: DomainClass where: [:each | each attribute similarTo: 'value']
Update table TABLE Set attribute = 'value' Where condition = 'value2' Instance := session readOneOf: DomainClass Where: [ :each | each condition = 'value2' ] Instance attribute: value.
Delete from TABLE Where condition = 'value' Instance := session readOneOf: DomainClass Where: [ :each | each condition = 'value2' ] Instance delete: value. Or (for multiple deletion) Session delete: DomainClass Where: [ :each | each condition = 'value2' ]
Select * from TABLE where attributes = 'value' Order by session read: DomainClass where: [:each | each attribute = 'value'];orderBy: [:each | each attribute = 'value']
Select * from TABLE where attributes = 'value' Group by session read: DomainClass where: [:each | each attribute = 'value'];groupBy: [:each | each attribute = 'value']

Each of your persisted objects should have an instance of GlorpClassModel in the descriptor system containing all the attributes of your class.

Defining relation between classes

attribute relation
newAttributeNamed: #email Used to define simple scalar/literal values such as Numbers, Strings, Dates, etc.
newAttributeNamed: #address type: Address Used to define 1:1 (one to one) relations with other objects of your domain model.
newAttributeNamed: #invoices collectionOf: Invoice Used to define 1:n (one to many) and n:m (many to many) relations of your class model with other models.
newAttributeNamed: #invoices collection: collectionClass of: Invoice Similar as the one above for 1:n and n:m relations, but you can define what kind of Collection is going to be used.
newAttributeNamed: #counters dictionaryFrom: keyClass to: valueClass Used to define an attribute that is a Dictionary where the key is key-Class and its values are instances of valueClass.

About

No description or website provided.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published