Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gradii/fedaco
Laravel Eloquent With Typescript
https://github.com/gradii/fedaco
active-record database mariadb nodejs orm postgresql sqlite typescript
Last synced: 18 days ago
JSON representation
Laravel Eloquent With Typescript
- Host: GitHub
- URL: https://github.com/gradii/fedaco
- Owner: gradii
- License: mit
- Created: 2021-08-07T04:21:17.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-09-27T14:29:51.000Z (about 1 month ago)
- Last Synced: 2024-10-12T13:32:36.295Z (27 days ago)
- Topics: active-record, database, mariadb, nodejs, orm, postgresql, sqlite, typescript
- Language: TypeScript
- Homepage: https://gradii.github.io/fedaco
- Size: 2.45 MB
- Stars: 10
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Fedaco Orm
[![Build Status](https://github.com/gradii/fedaco/workflows/CI/badge.svg)](https://github.com/gradii/fedaco/actions?query=workflow%3ACI)
### How To Use It
- setup a connection
```typescript
const db = new DatabaseConfig();
db.addConnection({
'driver' : 'sqlite',
'database': ':memory:'
});
db.bootFedaco();
db.setAsGlobal();
```
- define a model
```typescript
@Table({
tableName: 'user'
})
class User extends Model {
@PrimaryColumn
id;
@Column()
email;
@Column()
name;
@Column()
age;
@CreatedAtColumn()
created_at;
@UpdateAtColumn()
updated_at;
}
```
- fetch data
```typescript
const list = await User.createQuery().get();
```### Create Table
#### create a user table.
```typescript
const schemaBuilder = Model.getConnectionResolver()
.connection(connectionName)
.getSchemaBuilder();
;
await schemaBuilder().create('users', table => {
table.increments('id');
table.string('email').withUnique();
table.string('name');
table.string('age');
});
```### Features
- wrapped driver. unify all driver query api
- compile query builder to sql
- decorate to define model
- soft delete
- use relationship to link model
- relation can set dynamic constrain
- sqlite and mysql support### Notice
ecma class with field declaration not in constructor is not support. es2016 is support but es2022 is not.
field declaration can use `declare` keyword to declare field in constructor, then the field will not generated in class when enabled es2022
like this
```typescript
@Table({
tableName: 'user'
})
class User extends Model {
@PrimaryColumn()
declare id;
}
```