Fixed some issues with the DB initializer and added some stuff to README
This commit is contained in:
parent
b35d4926b1
commit
e6de9c1911
20
README.md
20
README.md
|
@ -59,6 +59,26 @@ row.commit(transaction)
|
|||
row.sync # true if synchronization successful
|
||||
```
|
||||
|
||||
### Explicitly request an existing row or explicitly creating a new row
|
||||
|
||||
```ruby
|
||||
#...
|
||||
row = Table.create({"pk1" => "new", "pk2" => "something", ...}) # returns nil if row exists
|
||||
|
||||
row = Table.get({"pk1" => "new", "pk2" => "something", ...}) # returns nil if row does not exist
|
||||
```
|
||||
|
||||
### Mapping results of a query to objects of a table
|
||||
|
||||
```ruby
|
||||
rows = Table.map("SELECT * FROM table_name WHERE row > 4 # AND ...")
|
||||
pp rows
|
||||
|
||||
#=>[<Table:0x000055da208232c8 @data={"row" => 5, ...}>,
|
||||
# <Table:0x00001238989cc89d @data={"row" => 7, ...}>,
|
||||
# ...]
|
||||
```
|
||||
|
||||
And that's really about it.
|
||||
|
||||
## Installation
|
||||
|
|
|
@ -132,8 +132,9 @@ module LPGAR
|
|||
@sync_query = <<~QUERY
|
||||
SELECT * FROM #{@table_name}
|
||||
WHERE #{selector}
|
||||
LIMIT 1;
|
||||
LIMIT 1
|
||||
QUERY
|
||||
puts @sync_query
|
||||
end
|
||||
|
||||
# Returns transaction class for this record.
|
||||
|
@ -363,10 +364,14 @@ module LPGAR
|
|||
@cols = conn.exec_prepared('lpgar_get_columns', [name]).map do |row|
|
||||
row['column_name']
|
||||
end
|
||||
raise StandardError, "table #{name} doesn't exist" if @cols.empty?
|
||||
|
||||
@cols_pk = conn.exec_prepared('lpgar_get_pk', [name]).map do |row|
|
||||
row['attname']
|
||||
end
|
||||
raise StandardError, "table #{name} doesn't exist" if @cols.empty?
|
||||
if @cols_pk.empty?
|
||||
raise StandardError, "table #{name} has no primary keys"
|
||||
end
|
||||
|
||||
@conn = conn
|
||||
@instances = {}
|
||||
|
|
Loading…
Reference in New Issue