1.0.44 • Published 6 months ago

duckdb-tinyorm v1.0.44

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

DuckDB Tiny ORM

Usage:

import 'reflect-metadata';
import { DuckDbRepository, Entity, Repository, DataTypeDecorator, BaseRepository, Id ,DuckDbLocation, DuckDbConfig } from 'duckdb-tinyorm';



//create instance in memory or use File, if File is specfied need to specify the filename
const duckDbRepository: DuckDbRepository = DuckDbRepository.getInstances({name: 'default', location: DuckDbLocation.Memory, filename: undefined})

@Entity
export class Subject {

    constructor(id: string = "", name?: string, description?: string, year: number = (new Date()).getFullYear()) {
        this.Id = id;
        this.Name = name;
        this.Description = description;
        this.Year = year;
    }

    @Id()
    @DataTypeDecorator('VARCHAR')
    Id: string ;

    @DataTypeDecorator('VARCHAR')
    Name?: string;


    @DataTypeDecorator('VARCHAR')
    Description?: string;


    @DataTypeDecorator('INT')
    Year: number;

}

@Repository(Subject)
class SubjectRepository extends BaseRepository<Subject, string> {
    constructor() {
        super(duckDbRepository);
    }
}


async function test() {
    const subjectRepository = new SubjectRepository();
    await subjectRepository.init();

    const subject1 = new Subject('JB', "Java Basic", "Java Basic", 2024);
    const subject2 = new Subject('OOP', "Java OOP", "Java Object Oriented Programming", 2024);


    //save records (as for now just insert a new record)
    await subjectRepository.save(subject1);
    await subjectRepository.save(subject2);

    //find all records
    const result = await subjectRepository.findAll();
    console.table(result);

    //find records by primary key
    const subjectFound1: Subject = await subjectRepository.findById("JB");
    console.info(subjectFound1);
    const subjectFound2: Subject = await subjectRepository.findById("OOP");
    console.info(subjectFound2);

    //delete one record by primary key

    await subjectRepository.removeById("JB");

    const amenities = await subjectRepository.findBy({ Year: 2024 }, ["Year"]);
    console.table(amenities);
}

test();
1.0.44

6 months ago

1.0.43

6 months ago

1.0.41

9 months ago

1.0.40

10 months ago

1.0.38

10 months ago

1.0.37

10 months ago

1.0.36

10 months ago

1.0.31

10 months ago

1.0.27

10 months ago

1.0.26

10 months ago

1.0.25

10 months ago

1.0.24

10 months ago

1.0.23

10 months ago

1.0.21

10 months ago

1.0.20

10 months ago

1.0.19

10 months ago

1.0.17

10 months ago

1.0.11

10 months ago

1.0.10

10 months ago

1.0.9

10 months ago

1.0.8

10 months ago

1.0.7

10 months ago

1.0.6

10 months ago

1.0.5

10 months ago

1.0.4

10 months ago

1.0.3

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago