Getting Started With Lift, Using Databases to Build Dynamic Sites - database

So I have been looking around the internet for a good explanation of how lift works concerning databases. I have not found anything very helpful yet. What I am looking for is a simple explanation or code example that can show how lift connects to its databases to perform transactions and how to use this to create new tables, models or update and edit existing tables.
For example: with django i fairly easily figured out how it generated database tables from model classes and executed updates on them through methods it inherited from the framework.
I am trying to create a simple app at the moment that would have users, information about them, posts on a website, etc.
I am currently reading through the available Lift books and would greatly appreciate more help in learning how to use lift.

Lift configures it's data source in Boot.scala.
if (!DB.jndiJdbcConnAvailable_?) {
val vendor =
new StandardDBVendor(Props.get("db.driver") openOr "org.h2.Driver",
Props.get("db.url") openOr
"jdbc:h2:lift_proto.db;AUTO_SERVER=TRUE",
Props.get("db.user"), Props.get("db.password"))
LiftRules.unloadHooks.append(vendor.closeAllConnections_! _)
DB.defineConnectionManager(DefaultConnectionIdentifier, vendor)
}
It can generate table schemas for you using Schemifier:
Schemifier.schemify(true, Schemifier.infoF _, User,Post,Tag,PostTags)
For general Lift project, you can just use Lift Mapper as an ORM tool, it's not complete but works for most of the cases.
You can refer to Lift WIKI and Simply Lift(Written by the Author) or Explore Lift.
From my perspective, the documents available so far are rather disappointing.
It's said the Lift in Action is very well written, but won't come out till this summer, you can read it from MEAP.

In the Exploring Lift book, the PocketChange example contains code showing how to define a User using MetaProtoUser and other features. I would start there for a better understanding of Lift, model and the built-in CRUD and User prototype objects.
http://exploring.liftweb.net/master/index-2.html#toc-Chapter-2
Keep in mind that the 'new' approach to DB integration will be via the Record. This is very much a work in progress, so I wouldn't rush to start learning it.
You can also look at the source for Lift in Action to get some ideas. Here's a link to the travel app built in the first couple chapters
https://github.com/timperrett/lift-travel
And to the source code for the entire book. Chapter 10 is the Mapper chapter.
https://github.com/timperrett/lift-in-action

The default ORM in Lift is Mapper which gives you among other things a quick path to CRUD functionality for your DB entities.
However if you would like a more traditional JPA persistence approach (or rather SPA since entities would in that case be written in scala), i usually find very useful the JPA-like sample application that is part of the Lift distribution. To try it out, assuming maven is installed, just type:
mvn archetype:generate -DarchetypeRepository=http://scala-tools.org/repo-snapshots -DarchetypeGroupId=net.liftweb -DarchetypeArtifactId=lift-archetype-jpa-basic_2.8.1 -DarchetypeVersion=2.3-SNAPSHOT -DgroupId=org.mycompany.myproject -DartifactId=MyProject -Dversion=1.0
This will create a MyProject Lift project, containing a simple library application with 2 entities (Author and Book) having a one-to-many relationship as well as CRUD snippets showing how you can create and edit such entities in a jdbc compliant database.

Related

Best way to save objects in database

The Story:
I’m trying to develop a big application in PHP. The main problem is that I have to deal with the objects and I need to apply CRUD operations. Ex: Suppose we have class diagram (Compiler):
Project { name:string, statements:list …}
Statement{ type:string }
IfStatement exend Statement { condition:Exp, …}
…
The question (What is the best design for ERD or database)
as I know I’ve two solutions:
Serialize the main object and save it in the DB
Make a table for each class in the class diagram and linking by foreign keys
Note: I’ve read about ORM but I think it’s similar to 1st solution
Serializing your objects in your database is in my opinion not a good solution.
You must be able to find and edit each object properties in your database.
It requires a simple logic structure, with relations and keys.
This way you'll be able to build a CRUD Admin Dashboard, read and edit all your data in a logical and reliable way.
MySQL Workbench is a real good starting point, it communicates with PhpMyAdmin, you can use it to build your database and create shemas.
Then if you're looking for a professional CRUD Generator I suggest this one: https://www.phpcrudgenerator.com/
[Disclaimer: I'm the author]
It can build your CRUD admin dashboard in a very simple way within a few minutes, and comes with many advanced features.
The Admin dashboard generated by the CRUD Generator is powered with Bootstrap 4, jQuery, PHP objects and TWIG templates.

How to integrate a PACS server (DCM4CHE) with personal database

Hi i am a newbie to programming. I have 100 or so CT scans stored on a PACS (dcm4che). I am trying to link all patients to a teaching file database (simple django application) which will have teaching points on each case. Can someone direct me to a tutorial or a brief direction to what sort of programming will integrate the two? i do realise the generic nature of the question. I have 20 days to work on this so am willing to start from scratch
Thanks
I would recommend against anything specific as diving into dcm4che. Instead if you would like to use standard API, you should use the QIDO-RS/WADO API provided by dcm4chee.
One of the main author did also document how to install such instance here
I would suggest to bind yiur django app or project to the appropriate dcm4chee databese. Since you have all priviliges just create a new table within dcm4chee database which has a simple foreign key column named SOPinstanceUid. In this column you just store the SOPinstanceUId of your preferred images. Then of course you can additionally provide all columns you need for your teaching problem.
You can of course also create a seperate database and bind your django app to both databases and use the SOPInstance uid also as main key to establish the relationship between dcm4chee db and teaching db.
Within your django app you can then of course manage your teaching table or db and query the filenames of the images which you have selected for teaching.The key of this relationship is the SOPInstanceUID of the dicom image.
This approach just needs some expertise in SQL, some knowledge of the preconfigured database and of course django and DICOM.

Advice on layered architecture (Win Forms + WinService; WCF; LINQ to SQL)

I'll try to explain as briefly as possible:
C#.Windows application for categories and descriptions of files.
Windows Forms - for the user
A library I want to be saved for future usage - I got nice algorithms for tasks with XML,Files,strings. In this case they are to serve the WF, but i don't want to keep them in the Form classes. I want to have them as a separate library with namespaces and classes in it. But I don't know what type of project or addition to the whole VS "Solution" that has to be.
Windows Service - get notifications on file changes and updates the same db the WF is using.
LINQ to SQL - for the data access
WCF - I am just throwing that here, because it seems that I need to use it(answer from a previous related topic) : https://stackoverflow.com/a/15998122/1356685
SO...yeah...architecture, architecture. Any guideline for a good architecture in my case is welcomed. Now I know in these conversations people start throwing terms like: "business logic","persistence layer","model layer" and what not. However I don't quite understand them, so please be specific.
Thanks in advance for the help !
Microsoft has a pretty extensive application architecture guide and their patterns and practices website has a lot of information and code samples showing you how to structure applications.
As for your 'library to be saved for future usage'... you can create a C# Class Library project and add it as a Reference in whatever applications you'd like to use it in.

Sharing necessary application data between developers in CakePHP

CakePHP has a process (schema shell and files) for sharing database structure between developers. However, there is often need to share some data (e.g. default user groups) as well. How have you solved this?
You can use fixtures for this. fixtures are small sets of data that can be used for testing or developing purposes. There is an interesting article about this here:
http://nuts-and-bolts-of-cakephp.com/tag/cake-fixtures/
There are also plugins which help with the whole db migration process though I didn't try them out yet you might find them interesting:
http://cakedc.com/pierre_martin/2010/02/05/cakephp-migrations-plugin-easily-version-and-deploy-whole-applications

Symfony 2: Build own DB access layer

I'm new here and on a research trip. We would like to use Symfony2 for a new project.
Now we have the problem that we need to use a company wide self-developed DB access layer.
We don't want to lose the whole Symfony/Doctrine layer for handling data.
Our idea is now to create or overwrite database access layer below Doctrine.
Something like creating a bridge (like PDO) between Doctrine and our DB access layer.
Has anyone an idea how we can do this or maybe someone has done similar things already and can provide us with an how-to?
Please no questions why. We just have to use the company access layer!
Thank you
http://forum.symfony-project.org/viewtopic.php?f=23&t=37637
I found the solution in Doctrine2 doc. It's pretty easy.
I needed for development and testing (frontend and console) about half a day
I've done it in 4 steps:
copy Doctrine\DBAL\Driver\OCI8 to a new folder.
rename files.
change functions to use own database access layer.
add in config file
doctrine:
dbal:
driver_class: /Path/To/Driver/Class
Doctrine has not much but a bit of information about Abstraction Layer:
Supporting Other Databases
If you believe this § of the doctrine documentation, you can see that you may use the Common package because it does not require the DBAL. Sadly, the same thing cannot be said of the ORM package. The best thing to do is probably to fork this package so that it supports your own DBAL.
Condolences for being obliged to use this DBAL.

Resources