Jump to content

Database First (Existing Data)


Recommended Posts

ProcessWire is an excellent framework for building just about anything, with great tools for permissions, input fields, and creating data structures.

With the Combo and Table profields, it's possible to handle just about any data.

These fieldtypes show the potential of ProcessWire to handle SQL tables in a more 'traditional' SQL table format, which leads to one area I wonder might have potential for a new feature.

In addition to ProcessWire, I also do some work with ASP.Net Core, and one of the nice features it has is the ability to work with existing SQL databases, so that you can either build your models in the framework, or use existing SQL Tables.

While working with any SQL data is possible in ProcessWire, it's a lot more hands on, with less built-in support.

InputFields and FieldTypes are separate, and there's no reason why an inputField can't be used for data input for any kind of data, and indeed there are some modules that use inputFields to edit custom table data.

What would be an amazingly useful addition to ProcessWire would be a module that allows mapping of inputFields to fields in an arbitrary SQL table without modifying the structure of the table itself.

This is something the open source Directus project does by using metadata tables to store data about to display input for existing SQL tables, without touching their structure, but documentation isn't great for that project.

I think ProcessWire has all the plumbing in place to enable this kind of functionality, and the Combo fieldtype gets pretty close, but still requires the combo table records to be associated with a ProcessWire page.

Obviously, existing SQL tables won't automatically map to pages, which means directly accessing them on the front-end via URL automatically isn't possible, but often this isn't required as they may be for backend use only, or for consumption within a ProcessWire page. The recent support for URL/Path hooks though, means that if there is a need to directly access existing SQL on the front end via URL, it should be possible to create a hook to do so.

I think adding the ability to create backend data entry for existing SQL tables would fully complete the ProcessWire philosophy of getting out of your way and not making assumptions about your content.

It's currently already best of class in terms of doing this regard to front end presentation, but it's still a bit opinionated about data structures at the back end. This is absolutely fine if you're building a web app from scratch, and works really well in most cases, but there are times where being able to quickly incorporate existing data structures would be useful.

To be clear, this isn't a replacement for the existing pages model, as that would be a huge and unecessary task to completely re-engineer ProcessWire, but rather an enhancement that can sit alongside all the good stuff that's already in ProcessWire so that it's possible to get ProcessWire to handle existing SQL data tables on the backend as neatly as it already does with its own data.

 

 

  • Like 5
Link to comment
Share on other sites

  • 1 month later...

Further to this, I've posted a feature request to Github, for a new method getColumns in WireDatabasePDO class, as this would enable:

$database->getColumns($table) which would be helpful for getting a list of custom table fields and their types.

there's already a getTables method and tableExists method, also a columnExists method, but currently no getColumns.

I might be able to have a go at building a module myself to map custom table columns to inputfields, and of course I could write a method myself, but if other people are accessing custom tables, it would seem to make sense to have a getColumns method in the core. 

Copying the columnExists method, removing the WHERE condition and returning an array of the results rather than a boolean is probably all that's needed to implement a getColumns method.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Similar Content

    • By HMCB
      Unlike the Integer input type, Decimal doesn’t allow for a default value. I’d love to see this added.
      I’m working on a mini project where this would come in really handy. The site admins would have all 7 fields pre-populated and they can then adjust as needed.
    • By creativejay
      Just one of those things I often find myself wishing for:
      Could a future update add a "Siblings" list tab (or make a "Children & Siblings" combined tab) to /page/edit/?
      Save + Next is a godsend, but in many cases I need to jump around instead of cycling through. Sometimes I just want to reference how I titled other pages under one parent to keep the naming consistent. Other times I'm deep enough in my page tree that it's a half-dozen or so more clicks than I'd like to get back to where I was.
      So far my workaround is to right-click on the parent's name in the Breadcrumb nav, and open the page tree in a new tab. But when editing a site often has me opening ten or more browser tabs at a time, each one I can cut out is a blessing. 
      Thanks for your consideration!
    • By steveooo
      Hello,
      just another wish on my list: Multiple instances for same field. E.g. I have got a simple "text" field that's just a CKEdtior textarea. If I want to use two or more text fields, I need to dublicate the "text" field to something like "text2".
      I know that every field is unique because of the database structure behind. Is is still possible to make something like this for this problem? Maybe save everything to same table in database but somehow add a "instanceNumber" field that separates "text1" from "text2"?
      It isn't a big thing, because cloning is easy. I really like to keep redundancies low and cloning fields isn't that great, so I share this wishlist. Maybe there is some way and I don't know about it, so let me know
    • By steveooo
      Hello,
      One thing that I really would like is a group fieldtype. This group fieldtype is just for grouping other fieldtypes. E.g.:
      "dates" as group field has "dateStart" and "dateEnd" (both datetime fieldtype) as fields.
      This would be a great feature!
      Is something like this currently possible?
    • By Robin S
      It occurred to me that a good addition to the forums would be some way for PW users to indicate support for a module idea. Similar to the Wishlist subforum but for functionality that belongs in a module rather than in the core.
      I'm thinking mainly of commercial modules, although if someone wanted to take up a module request and release it freely that would be cool.
      So users could propose a module idea, then others would vote for it (using likes or some special voting option) so that a vote means "I'd buy that", with the expectation of pricing in the general ballpark of Ryan's pro modules and Apeisa's PadLoper.
      As a beginner-intermediate developer I'm really enjoying working with PW and learning as I go - the API is so intuitive that I've been able to build my own solutions to things that in another CMS I would have been reliant on someone else's module to achieve. But there are things that I know are beyond my current skills, and for those things I look to third-party modules. My clients are non-profits and small businesses so I'm never likely to have the budget to commission a custom module alone. But there might be other PW users out there with similar needs and maybe that demand would make it worthwhile for an experienced developer to take on a proposal and release it as a commercial module. Currently there isn't a way to measure the demand for modules apart from occasional forum posts like "Is there a module that...?"
      Any thoughts on this?
      Here's a module request to start off with:
      I would be happy to buy a full-featured event calendar module. I've searched the module directory and the forums and Lindquist's module is the most feature-rich I've seen, but it's in an alpha proof-of-concept state and some important functions aren't implemented. Features I would be looking for are:
      Calendar grid interface in admin, allowing for easy addition and editing of events. (Nice but non-essential) Week and day views in admin, in addition to month view, with drag editing for event date and duration (I'm dreaming of something awesome like the dhtmlxScheduler interface or Fullcalendar interface). Although drag operations would really need an undo to correct accidental edits, so this may be more trouble than it's worth. Events are edited in a modal window, to avoid losing one's place in the calendar. Recurring events, with user-friendly selection of recurrence options. The ability to individually edit or remove an event that is a child of a recurring event (i.e. make an exception for that individual event). (Nice but non-essential) A couple of out-of-the-box minimal rendering options for the frontend (read-only calendar view, list view). This is the kind of module I need frequently. I've been lucky that I haven't had a client request a full event calendar since I've been using PW, but it's only a matter of time. I'm sure there are other PW users who need this and who would, like me, be happy to pay for such a module.
×
×
  • Create New...