Giter VIP home page Giter VIP logo

storm's Introduction

Storm

Storm is a Simple , Typed ORM for TypeScript.

Storm是一个简单,强类型基于TypeScript语言的ORM框架,它非常简单易学,没有侵入性的POCO实体,没有复杂的实体关系映射,且提供一套强类型的类SQL查询语法, 编写逻辑和结构基本和SQL语句一致,让你在使用SQL的简单直观开发体验的同时亦可享受强类型带来的好处。

demo

Examples

Select

db.from(Blog).Where(b=>b.Title == "Hello World!") 
//select * from Blog where Title = 'Hello World' 

//选择部分列
db.from(Blog).Where(b=>b.Title == "Hello World!").Select(b=>b.Id)
//select Id where Title = 'Hello World' 
db.from(Blog).Where(b=>b.Title == "Hello World!").Select(b=>{id:b.Id,title:b.Title})
//select Id as id,Title as title from Blog where Title = 'Hello World' 

//表关联自定义列
db.from(Blog)
.Join(User).ON((b,u)=>b.Creator==u.Id)
.Where<User>(u=>u.Name == "eric johnson")
.Select<Blog,User>((b,u)=>{b,Author:"Joe"})
//select b.Id,b.Title,'Joe' as Author from Blog b
//join User as u on b.Creator = u.Id
//where u.Name = 'eric johnson' 

//子查询
const subQuery = from(User).where(u => u.Name === "eric johnson").select(u => u.Id)
db.from(Blog).where(b => Sql.in(b.UserId, subQuery)
//select * from Blog
//where UserId in (select Id from User",
//                 where Name = 'eric johnson')

Insert

const blog = new Blog()
blog.Title = "Hello World!"
//插入全部字段
db.insert(blog)
db.insert({ Title: "Hello World!" } as Blog)
//insert into Blog (UserId,Title,Context) values (1,'Hello World!',null)

//插入部分字段
db.insertFields({ Title: "Hello World!" } as Blog)
//insert into Blog (Title) values ('Hello World!')

Update

//更新全部字段
db.update(blog, b => b.id === 1)
//update Blog set UserId = 1,Title = 'Hello World!',Context = null where Id = 1

//更新部分字段
db.updateFields({ Title: "abc" } as Blog, b => b.Id === 1)
//update Blog set Title = 'abc' where Id = 1

Delete

//条件删除
db.delete(Blog, b => b.Id === 1)
//delete from Blog where Id = 1

//复杂条件删除
const subQuery = from(User).where(u => u.Name === "eric johnson").select(u => u.Id)
db.delete(Blog,b => Sql.in(b.UserId, subQuery)
//delete from Blog 
//where UserId in (select Id from User",
//                 where Name = 'eric johnson')

//全表删除
db.deleteAll(Blog)
//delete from Blog

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.