GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - lambda-direct/datalayer

BranchesTags
Open more actions menu

Latest commit

 

History

209 Commits
209 Commits

Folders and files

NameName
Last commit message
Last commit date
src
src
 
 
.eslintrc
.eslintrc
 
 
.gitignore
.gitignore
 
 
.tslintignore
.tslintignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
package-lock.json
package-lock.json
 
 
package.json
package.json
 
 
tsconfig.json
tsconfig.json
 
 

Repository files navigation

MinorORM

MinorORM is an ORM framework for TypeScript. It offers you several levels of Database communication:

  • Typesafe Table View approach
  • Typesafe Query Builder
  • Simple SQL query execution

Minor ORM is highly influenced by Exposed and Jetbrains development methodology

Supported Databases

  • PostgreSQL

Links

In Progress

Installing

npm install @lambda-team/ltdl
yarn add @lambda-team/ltdl
bower install @lambda-team/ltdl

Connecting to database

import { DbConnector } from "@lambda-team/ltdl";

// connect via postgresql connection url
const db = await new DbConnector()
	.connectionString("postgres://user:password@host:port/db")
	.connect();

// or by params
const db = await new DbConnector()
	.params({
		host: '0.0.0.0',
		port: 5432,
		user: 'user',
		password: 'password',
		db: 'optional_db_name'
	}).connect();

Creating your first table and first migration

class UsersTable extends AbstractTable<UsersTable> {
  public id = this.int("id").primaryKey().autoIncrement();
  public name = this.varchar("name", { size: 512 });
  public email = this.varchar("email", { size: 512 }).unique();

  public tableName(): string {
    return "users";
  }
}

// lets create your first SQL migration to create initial schema
// > npx minor migrate

const migrator = new Migrator(db);
await migrator.runMigrations('./minor_orm/migrations')
// That's it!! No metaprogramming, no black magic, everything's imperative

Inserting into tables

Returned entity is of type ExtractModel which does have a set of typed fields

const email = '[email protected]'
const name = 'Full Name'

// returns inserted user
const user = await table.insert({ email, name }).first()

Simple querying with/without filters

For more complex filtering - see advanced querying

const email = '[email protected]'

const allUsers = await table.select().all()
const firstUser = await table.select().first()

const userWithEmail = await table.select(eq(table.email, email)).first()

// If you need to declare type explicitely
type User = ExtractModel<UsersTable>

const user: User = await table.select().first()
user.email
user.id

// Works perfectly!

Joins

class ItemsTable extends AbstractTable<ItemsTable>{
  id = this.int("id").primaryKey().autoIncrement();
  name = this.varchar("name");
	
  // many to one relation
  ownerId = this.int("owner_id").foreignKey(UsersTable, (t) => t.id); 
}

const query = usersTable.select().leftJoin(
	ItemsTable, 
	(ut) => ut.id,     // user id
	(it) => it.ownerId // item owner id
); 

const result = (await query.execute()).map((user, item) => {
	return { user, item };
});

// result would be
[{
    user: { id: 10, ... },
    item: { id: 1, ... }
},
{
    user: { id: 10, ... },
    item: { id: 2, ... }
},
{
    user: { id: 10, ... },
    item: { id: 3, ... }
},
{
    user: { id: 11, ... },
    item: { id: 4, ... }
},
{
    user: { id: 11, ... },
    item: { id: 5, ... }
}]

About

No description, website, or topics provided.

Resources

Readme
GPL-3.0 license
Activity
Custom properties

Stars

0 stars

Watchers

2 watching

Forks

0 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.