H1 2015 - db access support in Phobos

Vadim Lopatin via Digitalmars-d digitalmars-d at puremagic.com
Tue Feb 3 00:56:22 PST 2015


On Tuesday, 3 February 2015 at 08:23:56 UTC, Daniel Kozak wrote:
> On Monday, 2 February 2015 at 04:00:31 UTC, Vadim Lopatin wrote:
>> I would like to propose Java way for implementation of DB 
>> access (JDBC - Java DataBase Connectors).
>>
>> Standard library must contain only
>> * set of interfaces for uniform DB access
>>    * Connection - can create Statement or PreparedStatement, 
>> control transactions
>>    * Statement - can run update or query
>>    * PreparedStatement - same as Statement, but with parameters
>>    * ResultSet - DB query result row access
>>    * DataSource - can create connections, w/o parameters
>>    * Driver - interface which implements connection factory 
>> for particular DB types
>>    * Some useful classes like ConnectionPool
>> * factory method to create connection by URL and parameter set
>> * some method to register DB driver for factory - e.g. when 
>> called from driver's module __gshared static this()
>>
>> Drivers may be placed in separate packages in standard library 
>> or in some DUB packages.
>>
>> Look at https://github.com/buggins/ddbc
>> Currently it contains drivers for sqlite, MySQL and PostgreSQL.
>>
>>
>> If Andrey/Walter wish, I can prepare pool request based on 
>> code from ddbc.
>>
>> Best regards,
>>     Vadim
>
> Yep this is way to go, I have start implementing JPA for 
> Dlang(ddpa - dlang data persistence api):
>
> @Entity
> @(Table.name("nazev_tabulky").schema("nazev_schema"))
> class C
> {
>     @Id @(GeneratedValue.strategy(GenerationType.IDENTITY))
>     long id;
>
>     auto getId()
>     {
>         return this.id;
>     }
>
>     void setId(long id)
>     {
>         this.id = id;
>     }
> }
>
> void main() {
>     EntityManagerFactory emf = 
> Persistence.createEntityManagerFactory("test");
>     EntityManager em = emf.createEntityManager();
>     C obj = em.find!C(1);
> }

I did almost the same :) https://github.com/buggins/hibernated

// Annotations of entity classes

class User {
     long id;
     string name;
     Customer customer;
     @ManyToMany // cannot be inferred, requires annotation
     LazyCollection!Role roles;
}

class Customer {
     int id;
     string name;
     // Embedded is inferred from type of Address
     Address address;

     Lazy!AccountType accountType; // ManyToOne inferred

     User[] users; // OneToMany inferred

     this() {
         address = new Address();
     }
}

@Embeddable
class Address {
     string zip;
     string city;
     string streetAddress;
}

class AccountType {
     int id;
     string name;
}

class Role {
     int id;
     string name;
     @ManyToMany // w/o this annotation will be OneToMany by 
convention
     LazyCollection!User users;
}



More information about the Digitalmars-d mailing list