Table creation/Postal addresses: Difference between revisions

→‎{{header|Ruby}}: Add Ruby with PStore.
m (Never use {{header|SQLite}}, because this wrongly sets semantic property ((implemented in language::SQLite)), when SQLite is not a language.)
(→‎{{header|Ruby}}: Add Ruby with PStore.)
Line 301:
>>> </lang>
 
=={{header|Ruby}}+SQLite==
===With PStore===
PStore implements a permanent key store with transactions. This is a NoSQL database. Each transaction reads the entire database into memory, and then writes it again, so PStore is not good for large databases.
 
<lang ruby>require 'pstore'
require 'set'
 
Address = Struct.new :id, :street, :city, :state, :zip
 
db = PStore.new("addresses.pstore")
db.transaction do
db[:next] ||= 0 # Next available Address#id
db[:ids] ||= Set[] # Set of all ids in db
end</lang>
 
To put an Address inside this PStore:
 
<lang ruby>db.transaction do
id = (db[:next] += 1)
db[id] = Address.new(id,
"1600 Pennsylvania Avenue NW",
"Washington", "DC", 20500)
db[:ids].add id
end</lang>
 
===With SQLite===
{{trans|Python}}
 
Anonymous user