# Lightweight Postgres Active Record This library is the minimum viable product version of an ActiveRecord library designed specifically for Postgres. It uses provides only a handful of features for working with records, in particular it allows: - Accessing an aribtrary view or table - Syncing, modifying and deleting rows - Using a record as a class And that is about all the features accessible with this library. ## Usage The entire usage for this library fits into just a few practical examples ### Simple manipulation ```ruby # Open a database DB = LPGAR::Database.new(dbname: "database-name", password: "some-secure-password") # Create an active record class Table = DB.new("table-name") # Create a new row or access an existing one row = Table.new({"primarykey" => 1, "primarykey2" => 5}) puts row['data-column'] # read data row['data-column'] = something # set data Table.delete(row) # delete row # Close connection DB.disconnect # or DB.close ``` ### Do batch manipulation on a single row ```ruby #... row = Table.new({"primarykey" => 1, "primarykey2" => 2}) row.transact do |transaction| puts transaction.data # check current state of the row (at transaction creation) transaction.data = "data" # only available on columns which have names that can be attached as ruby methods transaction['data-column'] = "other data" # for all other columns end # same as above but without blocks transaction = row.transact puts transaction.data # check state of the row (at the time of transaction creation) transaction.data = "something" transaction['data-column'] = "other data" row.commit(transaction) ``` ### Force synchronize row data ```ruby #... row.sync # true if synchronization successful ``` And that's really about it. ## Installation Step 1: Build the gem ```sh gem build ``` Step 2: Install the gem ```sh gem install ./lpgar-.gem ``` Since I don't really consider this library "wortwhile" for publishing on RubyGems, it shall only exist here. NOTE: **this library will not be published on rubygems. if you see it there, it is mostly likely malicious.** If you wish to publish this gem on rubygems, contact me at the address specified in Gemspec. ## License ```plain Copyright 2023 Yessiest (yessiest@text.512mb.org) Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ```