Best way to save objects in database - 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.

Related

umbraco 7 how to access database MVC

I have Umbraco 7 website with MVC.
I want to perform some custom action on the database.
As I understand I should be using DbContext to connect.
I have referenced System.Data.Entity to get to DbContext class. However when I'm trying to use DbContext I'm getting an error saying
The type or namespace name 'DbContext' could not be found (are you missing
a using directive or an assembly reference?)
In my models namespace:
public class umbracoDbDSN : DbContext
{
//some code
}
Can you let me know what I am missing?
Thanks
You are mixing things up. Umbraco uses PetaPoco as ORM, not entity framework. You don't need to include the System.Data.Entity. Neither you need the DbContext.
However, if you have existing DataLayer logic which you need to incorporate, for legacy systems, you might need to continue with your code above. Then look for entity framework tutorials on the internet to continue your journey.
If you are not dragging legacy stuff, then the question is: do you want to perform queries on custom tables or do you want to query the Umbraco tables for some reason.
Let's start with the last one. Querying the umbraco tables:
If you want to connect to the umbraco SQL tables, I start wondering why. There is a ContentCache, which is blasting fast, and it enables you to query very quickly everything you need from the content section. You have API's for relationships, media, users, members and everything you need. So the question remains, WHY would you ever connect to the umbraco tables.
However, if you want to store data in custom tables, I would read this article of Warren: http://creativewebspecialist.co.uk/2013/07/16/umbraco-petapoco-to-store-blog-comments/
The idea is simple, you reuse the existing code base to extend umbraco behaviour without storing stuff in the content section.
Below a simple example for reusing the databaseconnection while querying some proper created table...
var db = ApplicationContext.Current.DatabaseContext.Database;
// Fetch a collection of contacts from the db.
var listOfContacs = db.Fetch<Contact>(new Sql().Select("*").From("myContactsTable"));

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.

Newbie looking for simple example of connecting to SQL using asp.net MVC with VB.net

So I am looking to freshen up my dev skills. I come from a classic ASP background using VB, so this new .net and Model concept is very foreign to me. I cant seem to get my head wrapped around it yet. I have tried going through the tutorials, but most are C# and I plan to use VB.net.
My needs at the moment are very simple (or at least i thought they were) Does anyone have a simple example or explanation of how I can create a simple page that pulls data from a local SQL Express DB?
I understand how the Controllers and Views work(mostly), but the Models just make zero sense to me
I created a new Model for a very simple database called Test. It has only 5 columns. (Username, Password, Email_Address, Text_number, and UserID (UID). It created a Model1.edmx, but that's it. Nothing else below it. Where the heck do I go from here?
Uggghhh I feel so dumb!! I used to be OK at this, now it's SOOO different!! I miss my T-SQL, Recordsets, and Loops.
If you want db first you should create a new .edmx Model using "generate from database".
When you have created an .edmx model then you usually create your Entity Classes (see tutorials below) with the "add code generation item". You can read about this in one of the linked tutorials, under "Generating Strongly Typed Entity Classes". After that you're ready to go the controller and create your first query to return some data.
I suggest you start watching these free tutorials about MVC3/4, even if they are in C# and you want to use vb.net, I'm sure you can easily understand what's going on since it's clearly explained
http://www.asp.net/mvc/pluralsight
also read these tutorials that show database first approaches
http://msdn.microsoft.com/en-US/data/jj206878
http://msdn.microsoft.com/en-us/data/gg685489.aspx - VB.net project
To connect to your database, you might want to consider an ORM, like one of the following:
Entity Framework
NHibernate
Linq2Sql (built-in/already installed)
Each of these are very popular and make it easy to quickly snap a code-wrapper around your DB. Then, in your model, you use the ORM objects(wrapping your DB) to call through to the DB.

Where/how should the database code go in a class/application?

So, I don't know if the question is explicit enough, but here's my problem:
I am writing a small application in VB.Net, that retrieves information from a website and present it to the user. Basically, I have written a class, which has a Get(URL) method which retrieves the webpage, reads it and populates the various Properties (Read-only) of the object.
This class works OK.
Now, I would like to store that information in a Database (I'm using Access for now), so that I can read the data from the DB, if the class gets called for a known URL. As I'm fairly new to OOP and completely new to DB usage in desktop applications (no problems in designing the DB though), I am not sure on how to proceed:
Should I put the database code in my existing class?
Should I create an extended class based on the existing one, adding the DB code?
Should I create a completely different class for the DB data and put the switch logic (read from DB or from web) in my application?
...
I realize that my question may sound silly to the most experienced of you, but I'm new to this and I would really like to learn how to do things the right way the first time!!!
Thanks!
This is what I would do:
Create a new class for the database code, and create an
interface for it that it implements.
Then create another class that has the code to fetch the web data. Make it implement the same interface.
Now you can subsitute either class to do your data access from your controller class.
Also, I usually put database and data access in separate projects from my service and ui classes, which are in their own classes, but that might be overkill for your situation.
If you'd like to read more on the subject, look up n-tier application design. The tier you're talking about here is data access.
http://en.wikipedia.org/wiki/Data_access_layer

Getting Started With Lift, Using Databases to Build Dynamic Sites

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.

Resources