GithubHelp home page GithubHelp logo

filebase's Introduction

= Warning

This code is alpha quality. Do not use in production.

= Introduction

Filebase is a very simple implementation for file-based databases. It comes with one built-in store that uses YAML, where each record is an individual file, but you can implement different storage classes if you like. It also provides a model class that allows you to treat your records (files) like classes, including a very basic associations implementation.

= Example

Assuming we have the file '[email protected]' in the 'db/person' directory and it looks like this:

	--- 
	name: Joe Smith
	organization: acme.com
	key: [email protected]

Then the code for accessing this "database" looks like this:

	class Person
	  include Filebase::Model[ :db / :person ]
	  has_one :organization
	end
	class Organization
	  include Filebase::Model[ :verify / :db / :organization ]
	  has_many :members, :class => Person
	end

	joe = Person.find( '[email protected]' )
	joe.name                                      # => 'Joe Smith'
	joe.organization.name	                        # => 'Acme, Inc.'
	
You can create and delete records much like a normal database. You find an object using it's "key" which is actually the filename (typically with an extension like '.yml') and can be accessed using the "key" attribute. Note that changing an object's key will not remove the original value - you have to explicitly delete it. So, in effect, you can copy a value by changing the key and saving it.

Also, a note on the associations - they are not automatically bi-directional. Putting a has_one in one place and a complementary has_many in another does not mean that if you change one, the other will change. This will be fixed in a later version, but for now, remember, these are files, and the data is synchronized between them in anyway.

Another limitation is that there is no real query language. You can access all of the records for a given model using #all, and then filter them as you would any array. But obviously if you find yourself need complex queries spanning several different classes, you should probably use a relational database.

filebase's People

Contributors

automatthew avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.