Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation & Project State #1

Open
mtshikomba opened this issue Feb 15, 2021 · 2 comments
Open

Documentation & Project State #1

mtshikomba opened this issue Feb 15, 2021 · 2 comments

Comments

@mtshikomba
Copy link

I like this library, but I haven't used it yet because I am not sure where to start. Is this project complete? I tried to find the documentation and I couldn't find any. Is there documentation for this project?

Thanks!

@SofianeLasri
Copy link

I know it's very late, but here's an example. It might be useful for someone else.

Here is an example on how to use jLoquent:

  1. Firstly, create your own package in order to keep jLoquent package clean.
  2. In your package, you will need to create at least three classes.
  • Main (optionnal but we obviously need an entry to run the code),
  • Configuration and Model. It is necessary to configure the database connection.
  • Model. Just like any Eloquent Model, it has to have a table name in singular. Ex: User.

Here are some declaration examples.

Configuration

package com.slprojects.test;

import org.jloquent.DBConfig;
import org.jloquent.DatabaseType;

public class Configuration implements DBConfig {

    @Override
    public DatabaseType getDatabaseType() {
        return DatabaseType.MYSQL;
    }

    @Override
    public String getHostName() {
        return "databaseHostname";
    }

    @Override
    public String getPortNumber() {
        return "databasePort";
    }

    @Override
    public String getDatabaseName() {
        return "databaseName";
    }

    @Override
    public String getUsername() {
        return "databaseUsername";
    }

    @Override
    public String getPassword() {
        return "yourPassword";
    }
}

Model (mine is called User)

package com.slprojects.test;

import org.jloquent.Model;

import java.sql.Timestamp;

public class User extends Model {
    private String name;
    private String email;
    private String password;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Timestamp getJoinedDate() {
        return joinedDate;
    }

    public void setJoinedDate(Timestamp joinedDate) {
        this.joinedDate = joinedDate;
    }

    private Timestamp joinedDate;
}

Main

package com.slprojects.test;

import org.jloquent.Connector;
import org.jloquent.DBConfig;

public class Main {
    public static void main(String[] args) {
        Connector connector = Connector.getInstance();
        DBConfig config = new Configuration();
        connector.setDBConfig(config);
        connector.open();

        User user = new User();
        user.setName("JohnDoe");
        user.setEmail("john.doe@example.com");
        user.setPassword("123456");
        user.setJoinedDate(new java.sql.Timestamp(System.currentTimeMillis()));

        user.save();
    }
}

If everything went well, you should see the sql insert command appear in the console.

NOTE: The DB driver is missing from the project. You should add the one that correspond you database type in the project depedencies. Example for MariaDB/MySQL based database:

<dependencies>
    <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>8.0.32</version>
    </dependency>
</dependencies>

Also note that the project is no longer maintained, and will most likely need to update classes and add new database types in the future. But the project remains usable in the current state.

@SofianeLasri
Copy link

I'm working on a fork. You can find it here: https://github.com/SofianeLasri/bjLoquent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants