Skip to content

Arkanain/json_search

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSON searching

Project implement basic functionality for working with JSON files as DB:

1. ActiveRecord
2. ActiveRelation
3. DBConnection
4. ActiveModel(to set right naming for HTML helpers)
5. Migration
6. Rails Generators(for models and migrations)

What you need to do if you don’t have your own table file: I made examples for model and table - language.rb and language.json which you can find in examples folder in project root directory. I use it for testing. So you can try already existing controller functionality after you will:

  • move languages.json file to app/services/db/tables folder.

  • move language.rb file to app/services/models folder.

What you need to do if you have your own table file: Add JSON file(Don't forget to change file name to model plural name. For example - 'languages.json') to app/services/db/tables folder. Table rows in file should have structure like:

[{
  "first_name": "John",
  "last_name": "Doe"
},
{
  "first_name": "Mark",
  "last_name": "Smith"
}]

Also you can create your own models and migrations with standard generators - rails g model User. This generator will create model and migration for it with create_table in up method and drop_table in down method. After you will run rake db:migrate you will be able to work with your table.

And that’s it, everything else will be created for you in runtime(database structure, correct table structure and model file).

After that you will be able to use standart model methods:

1. find
2. all 
3. where
4. matches( Example: Language.matches(params[:query_string], [:name, :type, :designed_by])
5. create
6. new
7. update_attributes
8. destroy
9. save
10. scope( Example row for model: scope :by_name, -> (name) { where(name: name) } )

and they will work like default methods in ActiveRecord (other methods still in progress).

You should keep in mind that method where support:

  • Inclusive searching(Full Designed By value is - Thomas Eugene Kurtz, but it quite enough just type - Thomas Eugene and you will take same result).

  • Negative searching(For that type of searching you need just add ‘-’ character before word or words and all matches will be excluded from results).

Web interface include two possible type of searching:

  • Global searching - Will be search by all fields in JSON file.

  • Field searching - This search is more complex. It allow you to include negative searching and searching in specified fields.

Also I implement few rails generators:

1. rails g model <model_name>
2. rails g migration <migration_name>

Methods for migrations:

1. create_table <table_name>
2. drop_table <table_name>
3. add_column <table_name>, <column_name>, <column_type>
4. remove_column <table_name>, <column_name>
5. rename_column <table_name>, <old_column_name>, <new_column_name>
6. change_column <table_name>, <column_name>, <column_type>

Also I added methods for default SQL types for create_table but you still can use default method column. Usage example:

create_table :users do |t|
    t.string :first_name
end

Possible field types is - string, text, integer, float, decimal, datetime, timestamp, time, date, boolean

I added few rake tasks for DB so you can use them too:

1. rake db:create - create db for project.
2. rake db:drop - remove project db.
3. rake db:migrate - run all migrations in db/migrate folder.
4. rake db:rollback - rollback all runned migrations.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published