. .


ST 4U 167: Deleting with Glorp

December 7, 2011 9:47:23.191




You can also watch it on YouTube:

Today we'll look at how to delete data from a database using Glorp - which means that we need to make a small modification to our #tableForEMP: method in class EmpSystem:

tableForEMP: aTable 
		createFieldNamed: 'first_name' 
		type: (platform varChar: 50).
		createFieldNamed: 'last_name' 
		type: (platform varChar: 50)) bePrimaryKey.

Note the small change - we've designated one column as the primary key. Ideally, that column would be more sensible than the one in this example, but the point is, you need to specify that. From here on out, Glorp will treat that column as the primary key, even if it's not specified that way in the database. Now we can actually do a deletion:

myEmp := session readOneOf: Emp where: [:each | each firstName = 'Wilma3'].
session delete: myEmp.

Executing that now works, and wraps the #delete: in a transaction for us. We can verify this by executing a query:


And inspecting the results:


And that's about it for today.


Technorati Tags: , ,

[st4u167-iPhone.m4v ( Size: 4667584 )]

posted by James Robertson

 Share Tweet This