Have you ever wanted to use your CSV files as a SQL database?
Ever wanted to be able to debug table views while prototyping your application locally?
Now you can.
Tabular DB allows you to use CSV files as a database and leverage existing CSV viewers to enhance the prototyping experience.
Use the create
method to add new records to a CSV file. Pass an array of instances to be created.
db = TabularDB.new('/path/to/csv/files')
users = [User.new(name: 'John', age: 25), User.new(name: 'Jane', age: 28)]
db.create(users) # Add new users to the CSV file
Use the read
method to retrieve data from a CSV file. You can specify options such as limit
, offset
, where
, and sort
to filter and sort the results.
db = TabularDB.new('/path/to/csv/files')
options = { limit: 10, offset: 0, where: 'row["name"] == "John"', sort: 'row["age"]' }
result = db.read(User, options)
puts result[:rows] # Output the rows that match the criteria
Use the update
method to modify existing records in a CSV file. You need to specify a where
condition to identify the records to update and provide the new values.
db = TabularDB.new('/path/to/csv/files')
where = 'row["name"] == "John"'
updated_values = { age: 30 }
result = db.update(User, where, updated_values)
puts result[:rows] # Output the updated rows
Use the delete
method to remove records from a CSV file. You can specify a where
condition to identify the records to delete.
db = TabularDB.new('/path/to/csv/files')
where = 'row["name"] == "John"'
db.delete(User, where) # Delete users with the name "John"
Use the create_if_not_exist
method to create a new CSV file with a specified header if it does not already exist.
db = TabularDB.new('/path/to/csv/files')
header = ['name', 'age']
db.create_if_not_exist(User, header) # Create a new CSV file with the specified header if it doesn't exist
Use the drop
method to delete a CSV file associated with a class.
db = TabularDB.new('/path/to/csv/files')
db.drop(User) # Delete the CSV file associated with the User class