-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
320 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import * as DetaOrm from '../src/index' // import * as DetaOrm from 'deta-base-orm' | ||
|
||
const run = async () => { | ||
|
||
// ✨ Define a schema for the kittens | ||
type KittenSchema = { | ||
name: string, | ||
cuteness?: number | ||
} | ||
|
||
const schema = new DetaOrm.Schema<KittenSchema>({ | ||
name: 'string', | ||
cuteness: { | ||
type: 'number', | ||
default: 0 | ||
} | ||
}) | ||
|
||
// 🛌 Create our Kitten base | ||
const Kitten = new DetaOrm.Base('Kitten', schema) | ||
|
||
// 🐱 Create a new kitten | ||
const line = await Kitten.save({ | ||
name: 'Line', | ||
cuteness: 8 | ||
}) | ||
console.log(line) | ||
|
||
// 🔍 Filter kittens by their name | ||
const withE = await Kitten.find({ | ||
name: { | ||
$con: 'e' // All kittens with the letter e in their name | ||
} | ||
}) | ||
console.log(withE) // [{name: 'Line', cuteness: 8}] | ||
|
||
// 🧵 Filter kittens by their cuteness | ||
const higherThan5 = await Kitten.find({ | ||
cuteness: { | ||
$gt: 5 // All kittens with a cuteness greater than 5 | ||
} | ||
}) | ||
console.log(higherThan5) // [{name: 'Line', cuteness: 8}] | ||
} | ||
|
||
run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.