Git Product home page Git Product logo

Comments (9)

okliv avatar okliv commented on May 20, 2024 3

sure, if we look at the ActiveRecord adapter
https://github.com/TrestleAdmin/trestle/blob/master/lib/trestle/adapters/active_record_adapter.rb
all methods (except default_attributes) looks pretty trivial to reproduce with sequel related methods...

i can even try to do it but hope for any approvements from contributors before i dedicate some time for this

from trestle.

okliv avatar okliv commented on May 20, 2024 1

i think it is little early to make a PR because i didn't test it enough, so here is just a snippet with sequel adapter code
https://gist.github.com/okliv/4822101ec49d16056fc56ad540ad7ca3

full list of changes to get it work is here: https://gist.github.com/okliv/52465d38a116688edf0033985e273d27

and UPD 2 (about auth plugin). i get it work too.

all changes i made for now (on auth plugin side) to get it expectably work are listed here https://gist.github.com/okliv/dbdcbb52076beaa9523ea972ca301203

from trestle.

rennanoliveira avatar rennanoliveira commented on May 20, 2024

I believe its possible to create a sequel adapter following the pattern at
'lib/trestle/adapters' and setting it on the :default_adapter config option on a project, right?

from trestle.

spohlenz avatar spohlenz commented on May 20, 2024

As @rennanoliveira mentioned, creating an adapter will be the correct way to do this. I'd definitely love to have a Sequel adapter included in Trestle core, although I'm not myself particularly familiar with it, so if you'd love to have a go then that'd be great.

If you find any of the adapter abstractions insufficient for Sequel, please let me know and we can try to make the necessary changes.

from trestle.

okliv avatar okliv commented on May 20, 2024

Today i have successfully seen my sequel model's data under /admin route so i can confirm it has a potential to be a frontend for sequel. during this quick test i had some errors too... mostly, NoMethodError for my sequel model class (i defined all missing methods, except model_name, "manually" for now just to remove exceptions):

#lib/trestle/resource.rb:155:in `default_model_name'
#fixed with Sequel::Model.plugin :active_model
model_name

#lib/trestle/attribute.rb:30:in `inheritance_column?'
inheritance_column

#lib/trestle/form/fields/check_box.rb:23:in `block (2 levels) in field'
human_attribute_name(attr)

So, i think, this methods need to be extracted to adapter too (or, will it be better to extend sequel class definition?)

In a few days i will try to test more deeply (for example, for now i've defined default_attributes as a simple Attribute.new() collection because reflections mapping for sequel models need more time)

going to test search and auth plugins...

UPD (search-plugin):

search is very basic one (not parametric) so there is no any problems at all (but, honestly, i need much more functional search like ransack-based for ActiveAdmin or https://github.com/djellemah/philtre for sequel)

as a quick workaround for now for me (just because there is only one text field that can be used for search) i've done this:

  #after i added a "philtre" gem  
  search do |q|
    Philtre.new( eval("{#{q}}") ).apply( MySequelModel.dataset )
  end

and now i can simply input into the search field something like this: title_like: "bread" or id: 1234 and filtering works with title LIKE "%bread%" or ID=1234 search snippets according to the philtre syntax. it is not very user friendly (especially, for the end-user), but in my case, something - is better than nothing

auth will try to look tomorrow...

from trestle.

spohlenz avatar spohlenz commented on May 20, 2024

It sounds like you're making some good progress @okliv. If it's alright, I'd love to see what your Adapter class looks like so far. Feel free to start a PR if you're so inclined.

  1. For model_name and human_attribute_name, these methods come from ActiveModel and IMO are pretty important for I18n. I'll look into how we can make these methods work even when the model doesn't define them. This would also entail making ActiveModel an explicit dependency (which should not be an issue since Rails is already a dependency).

  2. inheritance_column will almost definitely need to be moved into the Adapter class somehow. The methods inheritance_column and primary_key are used by the Attribute class to determine when to show fields in the automatic tables and forms, so perhaps we should have methods such as show_in_table?(attribute) and show_in_form?(attribute) on Adapter. This would allow adapters to also define additional logic for hidden fields if required.

What about auth and, especially, search plugins? Will it be comparable simple to adapt too, how do you think?

The trestle-search plugin at this stage has a "bring your own search method" approach, so I don't foresee any issues there.

For trestle-auth, I see one instance (https://github.com/TrestleAdmin/trestle-auth/blob/master/lib/trestle/auth/controller_methods.rb#L17) where I need to add an extra configuration block. Otherwise the configuration blocks should provide enough flexibility to bring your own User class with a non-ActiveRecord ORM.

from trestle.

spohlenz avatar spohlenz commented on May 20, 2024

I've just pushed a heap of commits that should pave the way for completing Sequel adapter support. I still need to finish testing in my Sequel demo app, but it's looking good so far.

from trestle.

spohlenz avatar spohlenz commented on May 20, 2024

Given the latest changes I have made to Trestle, here is my SequelAdapter module so far: https://gist.github.com/spohlenz/0b218de7a1636f5757bd6d30cc1abbb5

from trestle.

spohlenz avatar spohlenz commented on May 20, 2024

I've pushed a SequelAdapter to master (https://github.com/TrestleAdmin/trestle/blob/master/lib/trestle/adapters/sequel_adapter.rb).

It can be used by adding the following line to your trestle.rb:

config.default_adapter = Trestle::Adapters.compose(Trestle::Adapters::SequelAdapter)

from trestle.

Related Issues (20)

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.